Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
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...

EDIT

Browsers absolutely prevent User Custom Message, reasonably. Then decide when this compulsory message should be issued to user:

<body>
    <button onclick="activateReloader()">activate</button>
    <button onclick="deactivateReloader()">deactivate</button>
    <script>
        function onBeforeUnload(e) {
            e.preventDefault();
            alert("my custom message");//this not works, for demo only
            e.returnValue = '';
        }

        function activateReloader() {
            window.addEventListener('beforeunload', onBeforeUnload);
        }

        function deactivateReloader() {
            window.removeEventListener('beforeunload', onBeforeUnload);
        }
    </script>
</body>

This code states when message will be displayed to the user and when not.

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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

almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!