javascript onbeforeunload 不显示自定义消息 [英] javascript onbeforeunload not showing custom message

查看:42
本文介绍了javascript onbeforeunload 不显示自定义消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 onbeforeunload 事件的自定义消息并且运行良好,但我今天注意到它不再显示我的消息.而是显示您所做的更改可能无法保存"

I have custom message to onbeforeunload event and was working well but I noticed today that it's not showing my message anymore. Instead it shows "changes you made may not be saved"

window.onbeforeunload = function () {

    return 'Custom message'
}

谁能告诉我如何解决它?

can anyone please let me know how to fix it?

推荐答案

为了避免欺诈,Chrome 和 Chrome 决定移除在 onbeforeunload 对话框中设置自定义消息的功能.

To avoid scamming, chromium and hence chrome have decided to remove the ability to set a custom message in the onbeforeunload dialog.

请参阅 2016 年 2 月 18 日的错误报告.

See this bug report from the 18th of February, 2016.

onbeforeunload 对话框用于现代 Web 上的两件事:
1. 防止用户不慎丢失数据.
2. 诈骗用户.

onbeforeunload dialogs are used for two things on the Modern Web:
1. Preventing users from inadvertently losing data.
2. Scamming users.

为了在不阻止前者的同时限制它们对后者的使用,我们将不显示网页提供的字符串.相反,我们将使用通用字符串.

In an attempt to restrict their use for the latter while not stopping the former, we are going to not display the string provided by the webpage. Instead, we are going to use a generic string.

Firefox 已经这样做了[...]

Firefox already does this[...]

这篇关于javascript onbeforeunload 不显示自定义消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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