Any Bad Side Effects To Window.onbeforeunload Returning No Value?
I know that in Chrome and FF, if window.onbeforeunload returns null, then the dialog box will not pop up. But in IE, it pops up with the message 'null'. In order to make IE not c
Solution 1:
In Chrome, returning null
is equivalent to returning nothing or undefined
.
When nothing is returned, the dialog will not pop up.
Note: In your first example, the last line of the event listener is never reached, because either the if
or else
block returned.
Instead of returning null
, undefined
etc, just negate the condition : http://jsfiddle.net/f6uTw/
window.onbeforeunload = function() {
if (!shouldNotWarnBeforeUnload) {
return'Are you sure you want to leave the page?';
}
};
Post a Comment for "Any Bad Side Effects To Window.onbeforeunload Returning No Value?"