• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 738
  • Last Modified:

How to conditionally cancel body onUnload

I am trying to cancel the window from unloading when the user responds Cancel to the confirm dialog, like this:

function doTest(){
return confirm('Clck Ok for next page or click Cancel to stay on this page.');

<body onUnload="return doTest();">

This does not cancel the unLoad regardless of the choice.
1 Solution
Try this:
function doTest(){
if(!confirm('Clck Ok for next page or click Cancel to stay on this page.'))
 return true;

<body onUnload="return doTest();">
<a href = "http://www.yahoo.com">yahoo</a>

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now