onBeforeUnload对Chrome无法正常工作 [英] onBeforeUnload not working correctly for Chrome

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

问题描述

我已经使用这段代码了一段时间,直到昨天才运行良好:

I've been using this code for some time and it worked fine until yesterday:

window.onbeforeunload = function() {
    return "¡Atención! Si continúas no podrás volver atrás y podrías perder datos. Revisa todos los campos y termina el trabajo antes de moverte de esta página. ¿Seguro que quieres continuar?";
}

现在问题是Chrome显示:

The problem now is that Chrome shows this:

但Edge以正确的方式显示:

But Edge shows it the right way:

我做错了什么?

注意:语言不是问题,因为我尝试过英语和西班牙语。

Note: Language is not the problem because I've tried with both English and Spanish.

推荐答案

你没有做错任何事。谷歌决定做Mozilla做的事情,不再允许你显示自定义消息。它在Chrome 51中生效

You're not doing anything wrong. Google has decided to do what Mozilla did and not allow you to show a custom message anymore. It took effect in Chrome 51.

你仍然需要返回一些内容来触发内置对话框,但是你不再允许你确定该对话框的内容。

You still need to return something to trigger the built-in dialog, but you're no longer allowed to determine what that dialog says.

这是BugZilla条目,Mozilla决定在Firefox中使用它。

Here's the BugZilla entry where Mozilla decided to do it in Firefox.

这是Chrome问题,其中Google决定在Chrome中使用它。

Here's the Chrome issue where Google decided to do it in Chrome.

*(新的Chrome 51行为报告为错误,但自然它在几小时内关闭,因为它是b y design。)

*(The new Chrome 51 behavior was reported as a bug, but naturally it was closed within hours as it's by design.)

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

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