简体   繁体   English

onBeforeUnload 无法在 Chrome 上正常工作

[英]onBeforeUnload not working correctly for 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?";
}

The problem now is that Chrome shows this:现在的问题是 Chrome 显示了这个:

Chrome 屏幕截图

But Edge shows it the right way:但 Edge 以正确的方式展示了它:

边缘截图

What am I doing wrong?我做错了什么?

Note: Language is not the problem because I've tried with both English and Spanish.注意:语言不是问题,因为我已经尝试过英语和西班牙语。

You're not doing anything wrong.你没有做错任何事。 Google has decided to do what Mozilla did and not allow you to show a custom message anymore. Google 已决定做 Mozilla 所做的事情,不再允许您显示自定义消息。 It took effect in Chrome 51 .在 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.你仍然需要返回一些东西来触发内置对话框,但你不再被允许确定那个对话框说了什么。

Here's the BugZilla entry where Mozilla decided to do it in Firefox.这是Mozilla 决定在 Firefox 中执行的 BugZilla 条目

Here's the Chrome issue where Google decided to do it in Chrome.这是谷歌决定在 Chrome 中执行的 Chrome 问题

*(The new Chrome 51 behavior was reported as a bug , but naturally it was closed within hours as it's by design.) *(新的 Chrome 51 行为被报告为错误,但自然而然地在数小时内关闭,因为它是设计的。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM