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

330
Visualizações
How to really disable beforeunload?

A lot of web pages try to make you don't exit them by using the beforeUnload event on JS. Facebook, for instance, will show a warning if you try to use back / forward button , as the image below shows :

enter image description here

To avoid this i always used the code below to 'unbind' the event :

window.onbeforeunload = null;

But this is not working anymore. Even after running the code below, the warning message will still shows if i try to leave the page.

How to really get rid of these messages in a web application ? Facebook is only an example, i'm trying to do this using JS for study purposes.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The event is probably being registered via addEventListener rather than onbeforeunload. You could try adding a new event listener that overrides the previous one.

window.addEventListener("beforeunload", (event) => {
    event.stopImmediatePropagation();
}, true);

The third parameter being true causes the event to go all the way down, so any other listeners will be prevented.

about 4 years ago · Juan Pablo Isaza 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