FireFox不显示任何警告对话框窗口beforeunload事件 [英] FireFox doesn't display any warning dialog for window beforeunload event

查看:385
本文介绍了FireFox不显示任何警告对话框窗口beforeunload事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前正在使用最新版本的Firefox桌面浏览器。尝试捕获事件之前的窗口。下面的代码适用于IE,Chrome和Safari,但不适用于Firefox。

  window.addEventListener(beforeunload,function(e) {
var confirmationMessage =Test Test;
e.returnValue = confirmationMessage;
return confirmationMessage;
});


解决方案

b


为了防止不必要的弹出窗口,浏览器可能不会显示在beforeunload事件处理程序中创建的提示,除非页面已经被交互。
< blockquote>

如果用户之前没有与页面进行交互,则无法显示弹出窗口。另外,最好使用下面的代码:

  window.onbeforeunload = function(e){
var dialogText ='对话文本';
e.returnValue = dialogText;
返回dialogText;
};


Currently working the latest version of Firefox desktop browser. Trying to capture the window beforeunload event. Below code works for IE, Chrome and Safari but not with Firefox.

window.addEventListener("beforeunload", function(e) {
  var confirmationMessage = "Test Test";
  e.returnValue = confirmationMessage;
  return confirmationMessage;
});

解决方案

From Firefox's documentation:

To combat unwanted pop-ups, browsers may not display prompts created in beforeunload event handlers unless the page has been interacted with.

You cannot show pop-up if user didn't interacted with the page before. Also, it is better to use the following code:

window.onbeforeunload = function(e){
  var dialogText = 'Dialog text here';
  e.returnValue = dialogText;
  return dialogText;
};

这篇关于FireFox不显示任何警告对话框窗口beforeunload事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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