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

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