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

326
Visualizações
In Javascript how to detect Browser or Tab Close event?

In my Application i want to detect Browser or Tab close event and then for this event would like to submit form for logout function and clear user session.

I have tried window.onbeforeunload event but it is fire for all even i click link or refresh page.

Any one can please help me.

about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

There is no specific API to achieve what you want.

What you can do is the following:

  1. Issue access/session tokens with (relatively) short lifespans (like 1 minute)
  2. Have your frontend "continuously" refresh the tokens to keep the application signed in

In this way after a (relatively) small delay if the frontend is not running you end up with an expired session/access token and the user is effectively logged out.

Cons of this approach: if the user has a small window of connectivity problems their session will expire. If your system is a mobile application this might make your App very frustrating to use in various circumstances. Might not be a big problem if your use case is access from workstations.

about 4 years ago · Santiago Gelvez Relatório

0

You cannot detect a browser/tab close event natively in JavaScript. When the user closes a tab, all the script running on the page effectively ceases executing and no javascript code can run after that.

about 4 years ago · Santiago Gelvez 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