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.