• 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.');
}i

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

This does not cancel the unLoad regardless of the choice.
0
vogtster
Asked:
vogtster
1 Solution
 
archrajanCommented:
Try this:
<script>
function doTest(){
if(!confirm('Clck Ok for next page or click Cancel to stay on this page.'))
 location.href=location.href
 else
 return true;
}</script>

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

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