I have a system in which the page must not be closed/unloaded until a certain condition is met. This is to force staff to complete very important information.
I know it is NOT good UI practice, I totally agree but in this case after lengthy discussions it is 100% necessary.
I have tried the following code:
$(window).bind('beforeunload', function (event) {
cancelEvent(event);
stopEvent(event);
});
function cancelEvent(e) {
if (!e) e = window.event;
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
}
function stopEvent(e) {
if (!e) e = window.event;
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
}
The above code does not work.
Is there anyway to kill the unload event and keep the page shown?
The targeted browsers are IE 7-9 so even if it doesn't work on modern browsers that would be fine.
Thanks again.