Ben
Ben

Reputation: 3

window.onbeforeunload not working on Firefox 46 in a popup window, all other browsers work

Having an issue with Firefox 46, on all the other browsers it work fine. Upon exit from the page I ask the following question. Firefox ignores it completely. Help please!

window.onbeforeunload = ThisCheckExittingPage;

var ThisCheckExitWindow = 1;

// Checks before exitting
// ThisCheckExitWindow = 1;

// Does NOT check before exitting
// ThisCheckExitWindow = 0;

function ThisCheckExittingPage() {

    if (ThisCheckExitWindow == 1)
    {
        return "You are about to exit this page.";
    }
}

Upvotes: 0

Views: 629

Answers (1)

ivan_pozdeev
ivan_pozdeev

Reputation: 36008

This looks like by design, as WindowEventHandlers.onbeforeunload - Web APIs | MDN has this note:

To combat unwanted pop-ups, browsers may not display prompts created in beforeunload event handlers unless the page has been interacted with. Firefox has implemented this policy since Firefox 44 (Bugzilla).

As the relevant patch shows, the mUserHasInteracted flag variable is set after a mouse or keyboard event happens in the window.

Upvotes: 2

Related Questions