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

181
Visualizações
Unable to detect when closing browser tab in Angular

I am trying to show some confirmation box when user is going to close the browser window using angular but as per my code its not working. My code is given below.

app.component.ts:

import { AfterViewInit, Component, OnInit, ElementRef, HostListener } from '@angular/core';
@HostListener('window:beforeunload', ['$event'])
  beforeunloadHandler(event) {
    if(confirm("Are you sure to close ")) {
      console.log("Implement close functionality here");
    }
    //return false;
    //I have used return false but you can your other functions or any query or condition
  }

Here I need when user will close tab on browser this confirmation box should appear but the above code I could not get any such alert. If anybody has any new solution please help to resolve this issue.

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