javascript - 使用自定义消息离开页面留在页面上

标签 javascript onbeforeunload

我正在尝试在要求离开页面或留在页面上的弹出窗口中放置一些自定义文本。 我试过了

window.onbeforeunload = function () {
             return "This is my custom message";
         };

但是当 IE 显示我的消息时,Mozilla 和 Chrome 仍然说出它们自己的消息。 所以我想做的是它应该显示带有离开和留下按钮的自定义消息。 我确信我在一些网站上看到过,虽然我不记得是哪个网站 :(

这可能吗?

最佳答案

Firefox 4 及更高版本不会显示您的自定义消息。另见 this answer :

From MDN:

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

这个“Bug”实际上是一个(恕我直言,有问题的)特性..所以没有办法在 Firefox 4 中显示消息。如果你认为它应该改变,评论那个 Bug 这样 Firefox 开发者就会知道人们实际上希望能够显示自定义字符串。

关于javascript - 使用自定义消息离开页面留在页面上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8699892/

相关文章:

javascript - 为什么即使在 Internet Explorer 中返回 null,jquery beforeunload 也会显示一条消息

javascript - Google 应用程序脚本 .toUpperCase 跳过数字

javascript - 在 db.open() 回调中使用导出 - mongoose/express

javascript - 如何在打印时隐藏打印按钮?

javascript - 尝试让 Chrome 使用 onbeforeunload 显示即将离开的页面

google-chrome - Google Chrome扩展程序中的onbeforeunload事件是否会触发popup.html?

javascript - 无法避免 'onbeforeunload' 事件的默认警告

javascript - 沙箱 WebGL 插件

java - Tapestry Prototype 在区域更新时按 ID 选择元素

asp.net - onbeforeunload 事件需要 Jquery 帮助