简体   繁体   中英

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). 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...

This was prohibited in browsers a long time ago (Chrome 51 is from 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.

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.

onbeforeunload dialogs are used for two things on the Modern Web:

  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=587940

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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