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

大兔子大兔子 提交于 2019-12-02 22:10:11

问题


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.";
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/37360518/window-onbeforeunload-not-working-on-firefox-46-in-a-popup-window-all-other-bro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!