Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda