I have an AJAX-based grid control.
We hook into the window.onbeforeunload event to check if they have unsaved data and if so present them with a message \"Are you s
If you want to trigger your postback by a hyperlink, there is a simple workaround: Instead of
<a href="javascript:submitFunction();">Submit</a>
or
<a href="javascript:;" onclick="submitFunction();">Submit</a>
just use this code:
<a href="#" onclick="submitFunction();">Submit</a>
It seems that IE fires the onbeforeunload event if the content of the href-attribute of a hyperlink is not the current page (which the sharp character indicates).
This is really weird, are you sure your Ajax call isn't loading a new link?
Be sure you read this relevant specification: onbeforeunload spec
See if the Ajax call maybe triggers any of the actions listed in the To invoke table.
I did something like this:
inside body tag:
var allowConfirm = true;
window.onbeforeunload = confirmExit;
function confirmExit()
{
if(allowConfirm)
return "Are you sure you want to navigate away from this page?";
else
allowConfirm = true;
}
When I Logout, I call this script:
allowConfirm = false; return window.location.href;