We would like to throw a specific message before a user closes the browser. Is there a mechanism which will work across all major browsers (like IE, firefox, chrome, opera)
+3
A:
Check onbeforeunload:
window.onbeforeunload = function (e) {
var e = e || window.event;
if (has_message_to_throw) {
// For IE and Firefox
if (e) {
e.returnValue = 'Specific message';
}
// For Safari
return 'Specific message';
}
};
KennyTM
2010-04-25 19:46:29
I tried the following function, but it doesn't work for IE 8, latest version of Opera. What am I missing here?window.onbeforeunload = function (e) { var message = "Your confirmation message goes here.", e = e || window.event; // For IE and Firefox if (e) { e.returnValue = message; } // For Safari return message;};
Samuel
2010-04-26 11:17:54
@Samuel: Looks like Opera doesn't support `onbeforeunload` (Ref: http://www.zachleat.com/web/2008/04/22/dont-let-the-door-hit-you-onunload-and-onbeforeunload/).
KennyTM
2010-04-26 16:18:46
IE8 also didn't work and that is quite important for us.
Samuel
2010-04-27 10:41:37