Firefox 4 onBeforeUnload 自定义消息

发布于 10-25 16:37 字数 375 浏览 4 评论 0原文

在 Firefox 3 中,我能够编写自定义确认弹出窗口:

window.onbeforeunload = function() {
   if (someCondition) {
      return 'Your stream will be turned off';
   }
}

现在在 Firefox 4 中,它不会显示我的自定义消息。它提供的默认消息甚至不准确地反映了我的应用程序的功能。

firefox 4 recognize

可以覆盖此默认消息吗?

In Firefox 3, I was able to write a custom confirmation popup with:

window.onbeforeunload = function() {
   if (someCondition) {
      return 'Your stream will be turned off';
   }
}

Now in Firefox 4, it does not show my custom message. The default message that it provides is not even accurate to what my application does.

firefox 4 confirm

Can this default message be overridden?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

辞别2024-11-01 16:37:07

来自 MDN

请注意,在 Firefox 4 及更高版本中,返回的字符串不会向用户显示。请参阅错误 588292

这个“Bug”实际上是一个(恕我直言,有问题的)功能。所以没有办法在 Firefox 4 中显示该消息。如果您认为应该更改,请评论该错误,以便 Firefox 开发人员知道人们实际上希望成为能够显示自定义字符串。

From MDN:

Note that in Firefox 4 and later the returned string is not displayed to the user. See Bug 588292.

This "Bug" is actually a (imho questionable) feature.. so there's no way to display the message in Firefox 4. If you think it should be changed, comment on that bug so the Firefox developers will know that people actually want to be able to show a custom string.

月下客2024-11-01 16:37:07

除了上面的答案之外,我还改进了解决方法。

我这里用的是jquery。您也可以使用默认的 javascript 函数。

$(window).bind('beforeunload', function() {
    if(/Firefox[\/\s](\d+)/.test(navigator.userAgent) && new Number(RegExp.$1) >= 4) {
        if(confirm("Are you Sure do you want to leave?")) {
            history.go();
        } else {
            window.setTimeout(function() {
                window.stop();
            }, 1);
        }
    } else {
        return "Are you Sure do you want to leave?";
    }
});

也在 Firefox 11 中进行了测试和工作。 :)

Addition to the above Answer, I have improved the workaround.

I have used jquery here. you can use default javascript funciton as well.

$(window).bind('beforeunload', function() {
    if(/Firefox[\/\s](\d+)/.test(navigator.userAgent) && new Number(RegExp.$1) >= 4) {
        if(confirm("Are you Sure do you want to leave?")) {
            history.go();
        } else {
            window.setTimeout(function() {
                window.stop();
            }, 1);
        }
    } else {
        return "Are you Sure do you want to leave?";
    }
});

Tested and working in firefox 11 as well. :)

‘画卷フ2024-11-01 16:37:07

我的解决方法是在 onbeforeunload 中显示警报:(

window.onbeforeunload=function() {
    if ( /Firefox[\/\s](\d+)/.test(navigator.userAgent) && new Number(RegExp.$1) >= 4) {
        alert("Blah blah. You have to confirm you are leaving this page in the next dialogue.");
    }
    return "Blah blah."; 
} 

它在 Firefox 中显示两个对话,在其他地方显示一个对话。)

My workaround is to show alert in onbeforeunload:

window.onbeforeunload=function() {
    if ( /Firefox[\/\s](\d+)/.test(navigator.userAgent) && new Number(RegExp.$1) >= 4) {
        alert("Blah blah. You have to confirm you are leaving this page in the next dialogue.");
    }
    return "Blah blah."; 
} 

(It shows two dialogues in Firefox, one dialogue elsewhere.)

请你别敷衍2024-11-01 16:37:07

尝试用确认消息来实现它,

window.onbeforeunload=function(){
   return confirm("Are you sure??");
}

当然当用户确认时会显示 FF4 消息,
因此,您最好在登录/访问时在每个站点上显示一次。
一块 cookie 应该可以解决问题。

Try implementing it with a confirm message,

window.onbeforeunload=function(){
   return confirm("Are you sure??");
}

of course when the user confirms then the FF4 message is shown,
so you maybe better display this once per site on login/visit.
A cookie should do the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文