Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

332
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda