在 Firefox 3中,我能够编写一个自定义确认弹出窗口:
window.onbeforeunload = function() {
if (someCondition) {
return 'Your stream will be turned off';
}
}
现在在 Firefox 4中,它不显示我的自定义消息。它提供的默认消息甚至与我的应用程序所做的都不准确。
可以覆盖此默认消息吗?
在 Firefox 3中,我能够编写一个自定义确认弹出窗口:
window.onbeforeunload = function() {
if (someCondition) {
return 'Your stream will be turned off';
}
}
现在在 Firefox 4中,它不显示我的自定义消息。它提供的默认消息甚至与我的应用程序所做的都不准确。
可以覆盖此默认消息吗?
除了上面的答案,我还改进了解决方法。
我在这里使用了 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 中测试和工作。:)
我的解决方法是在 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 中显示两个对话,在其他地方显示一个对话。)
尝试使用确认消息来实现它,
window.onbeforeunload=function(){
return confirm("Are you sure??");
}
当然,当用户确认时,会显示 FF4 消息,因此您最好在登录/访问时每个站点显示一次。一个cookie应该可以解决问题。