onBeforeUnload suddenly not working as expected

核能气质少年 提交于 2019-12-25 07:49:23

问题


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:

Changes you made may not be saved.

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

Or, am I doing it wrong?


回答1:


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

A window’s onbeforeunload property may be set to a function that returns a string that is shown to the user in a dialog box to confirm that the user wants to navigate away. This was intended to prevent users from losing data during navigation. Unfortunately, it is often used to scam users.

Details here



来源:https://stackoverflow.com/questions/38428636/onbeforeunload-suddenly-not-working-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!