Skip to content Skip to sidebar Skip to footer

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?';
    }
};

Solution 2:

On Internet Explorer 11, null will still create the beforeunload popup. One of those rare instances where undefined and null work differently.

ie11 shows onbeforeunload popup with a value of null

Post a Comment for "Any Bad Side Effects To Window.onbeforeunload Returning No Value?"