window.onbeforeunload在弹出窗口中的Firefox 46上不起作用,所有其他浏览器都可以工作 [英] window.onbeforeunload not working on Firefox 46 in a popup window, all other browsers work

查看:120
本文介绍了window.onbeforeunload在弹出窗口中的Firefox 46上不起作用,所有其他浏览器都可以工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firefox 46出现问题,在所有其他浏览器上都可以正常工作. 从页面退出后,我会问以下问题. Firefox完全忽略了它. 请帮忙!

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

推荐答案

这看起来像是设计的

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

为防止不必要的弹出窗口,浏览器可能不会显示创建的提示 在beforeunload事件处理程序中,除非页面已交互 和.自Firefox 44( Bugzilla )以来,Firefox已实施此政策.

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).

相关补丁所示,设置了mUserHasInteracted标志变量在窗口中发生鼠标或键盘事件后.

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

这篇关于window.onbeforeunload在弹出窗口中的Firefox 46上不起作用,所有其他浏览器都可以工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆