onBeforeUnload突然无法按预期工作 [英] onBeforeUnload suddenly not working as expected

查看:63
本文介绍了onBeforeUnload突然无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码段已将近2年了.那很好,直到我看到它今天无法在 Google Chrome 51.0.2704.103m 版本上工作.

I was using this snippet for almost 2 years. It was fine then, until I saw it was not working today on Google Chrome version 51.0.2704.103m.

$(window).on('beforeunload', function () {
    return "Are you sure you want to exit this page?";
});

它不显示我的自定义消息,而是显示:

It doesn't show my custom message but instead just show:

您所做的更改可能不会保存.

我们的浏览器是否仍支持覆盖onbeforeunload消息?因为此问题与 Mozilla Firefox 47.0.1版相同.

Is overriding onbeforeunload message is still supported on our browsers? Because this issue is same with Mozilla Firefox version 47.0.1.

或者,我做错了吗?

推荐答案

从版本51开始的Chrome不再支持beforeunload上的自定义消息.

Chrome from Version 51 onwards no longer supports custom messages on beforeunload.

可以将窗口的onbeforeunload属性设置为一个函数,该函数返回在对话框中显示给用户的字符串,以确认用户要离开.目的是防止用户在导航期间丢失数据.不幸的是,它经常被用来欺骗用户.

详细信息此处

这篇关于onBeforeUnload突然无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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