I want to execute an action method when the user is abandoning a particular page using jQuery.
The page has the following code:
window.onbeforeunload=navigationError;
var dont_confirm_leave = 0; var leave_message = 'You sure you want to leave?';
function navigationError(e)
{
if(dont_confirm_leave!==1)
{
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = leave_message;
//e.stopPropagation works in Firefox.
if (e.stopPropagation)
{
e.stopPropagation();
e.preventDefault();
}
//return works for Chrome and Safari
return leave_message;
}
}