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

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

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 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