NickMalloy
asked on
Alert when navigating away from page
I'm working with an asp.net page within a masterpage. I am trying to alert people on an entry page when they try and leave the page. The message pops up just fine, but when I click cancel it still navigates away. What am I doing wrong?
jQuery(function ($) {
/* global on unload notification */
warning = true;
if (warning) {
$(window).bind("unload", function () {
if (confirm("Do you want to leave this page") == true) {
//they pressed OK
alert('ok');
} else {
// they pressed Cancel
// alert('cancel');
return false;
}
});
}
});
Nevermind my last comment, did not read the code entirely...still looking...
Check this thread:
http://www.mkyong.com/jquery/how-to-stop-a-page-from-exit-or-unload-with-jquery/
Preece
http://www.mkyong.com/jquery/how-to-stop-a-page-from-exit-or-unload-with-jquery/
Preece
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
return false;
after
alert('ok');
will do the trick