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

454
Vistas
How does Angular differentiate between refresh event and close browser/close tab event?

How does Angular differentiate between refresh event and close browser/close tab event?

I tried to listen to the event beforeunload, but I found that this event is fired whether I refresh the web page or close the browser

@HostListener('window:beforeunload', ['$event'])
  public beforeunloadHandler() {
  console.log('Click the refresh page button, or close the browser, this time will be called ');
}

The desired effect: I need to send a request when closing the browser: clear the token on the server side, but when refreshing the webpage, I don't want to trigger the request to clear the token, how can I distinguish between the refresh webpage event and the browser close event?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Simple answer is that you can't distinguish them. To the browser their all unload events (either it's actually refresh, closing the tab, or closing the browser).

For this reason, most commonly session is kept alive by updating it. And when it doesn't receive any more updates after certain period, then the session is terminated.

Have your backend keep the token alive, and make the frontend update it (e.g on mouse move or when making http calls) whatever the function should be on the frontend that's letting backend know, token should be kept alive.

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