简体   繁体   English

ASP.NET JavaScript 始终显示默认警报消息

[英]ASP.NET JavaScript Always Shows Default Alert Message

Despite of JavaScript located in ASP.NET Core Page (cshtml), getting always a default message like "Changes Are Made..." from EDGE Browser (or CHROME is the same).尽管 JavaScript 位于 ASP.NET 核心页面 (cshtml) 中,但始终会从 EDGE 浏览器(或 CHROME 相同)中获取默认消息,例如“已进行更改...”。 Is there a way to use Custom Message?有没有办法使用自定义消息?

window.onbeforeunload = function confirmExitPage() {
    event.preventDefault();
    return "My Custom Message I like to Show?";
}

I have already seen similar questions in SO, but none of them supplies a solution...我已经在 SO 中看到过类似的问题,但没有一个提供解决方案......

This was prohibited in browsers a long time ago (Chrome 51 is from 2016).这在很久以前的浏览器中是被禁止的(Chrome 51 是从 2016 年开始的)。 You can't show a custom message anymore.您无法再显示自定义消息。

Starting with Firefox 44, Chrome 51, Opera 38, and Safari 9.1, a generic string not under the control of the webpage will be shown instead of the returned string.从 Firefox 44、Chrome 51、Opera 38 和 Safari 9.1 开始,将显示不受网页控制的通用字符串,而不是返回的字符串。

https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event#compatibility_notes https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event#compatibility_notes

Reading the issue on the Chromium issue tracker it was about avoiding bad sites using it to try scamming users.在 Chromium 问题跟踪器上阅读该问题是为了避免不良网站使用它来尝试欺骗用户。

onbeforeunload dialogs are used for two things on the Modern Web:在现代 Web 上,onbeforeunload 对话框用于两件事:

  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.为了在不停止前者的情况下限制它们对后者的使用,我们将不显示网页提供的字符串。

https://bugs.chromium.org/p/chromium/issues/detail?id=587940https://bugs.chromium.org/p/chromium/issues/detail?id=587940

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

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