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.
<script>
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();" />
Apparently IE7 doesn't like the part where I set onBeforeUnload = null; SO it just ignored that. The result would have been disaster but for a stroke to testing luck. Here's the simple yet crucial change that I made:
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();" />
<script>
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();" />
I know I have mentioned it before but IE7 sucks! I use it at work and I must admit the new tab interface works nicely, but all the crap they changed makes me say "IE7 SUCKS"
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();" />
4 Comments:
I've actually found a way to detach the onbeforeunload event handler without having to use a global flag and all that. However, it's only compatible for Firefox (2?) and IE7. The product I'm working on is only supported for these two browsers, but others might need to support other, older variants. Nevertheless:
Firefox 2:
window.onbeforeunload = null;
IE 7:
window.document.body.onbeforeunload = ";";
Hope this helps someone out there, as it did for me.
For IE, you can also use :
window.document.body.onbeforeunload = null;
Same thing for onunload event :
window.document.body.onunload = null;
But IE still sucks !
[url=http://www.kfarbair.com][img]http://www.kfarbair.com/_images/_photos/photo_big8.jpg[/img][/url]
בית מלון [url=http://www.kfarbair.com]כפר בעיר[/url] - אינטימיות, [url=http://kfarbair.com/services.html]שקט[/url] . אנחנו מציעים שירותי אירוח מיוחדים גם ישנו במקום שירות חדרים המכיל [url=http://www.kfarbair.com/eng/index.html]ארוחות רומנטיות[/url] במחירים מיוחדים אשר מוגשות ישירות לחדרכם...
לפרטים אנא לפנות לעמוד המלון - [url=http://kfarbair.com]כפר בעיר[/url] [url=http://www.kfarbair.com/contact.html][img]http://www.kfarbair.com/_images/apixel.gif[/img][/url]
is rollo weeks dating a girl named jesse [url=http://loveepicentre.com/]singles all together minnesota[/url] ancientbrit personals http://loveepicentre.com/ cross road dating
Post a Comment
<< Home