OnBeforeUnload, IE7, Assigning event handlers to null and the problems that arise
This IE7 issue almost totally screwed me at work. Image if a JS designed to keep users from leaving a page before placing their order suddenly started telling all users that they were leaving and their orders weren't being placed, even though they were. Ouch.. that'd probably have someone gunning for my job. But that almost happened. Here's how MSoft and sucky IE7 almost did it to me: I had a script like this.
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "Leaving this page will cause all unplaced orders to be discarded. Are you sure you want to leave the page?";
}
</script>
. . . . .
<input type="image" src="/lgrequest.gif" onclick="javascript: window.onbeforeunload = null; document.forms[0].submit();" />
var goodExit = false;
window.onbeforeunload = confirmExit;
function confirmExit()
{
if (!goodExit)
return "Leaving this page will cause all unplaced orders to be discarded. Are you sure you want to leave the page?";
}
</script>
. . . . .
<input type="image" src="<%=AppService.BASEDIR%>/images/lgrequest.gif" onclick="javascript: goodExit = true; window.onbeforeunload = null; document.forms[0].submit();" />