Angular 10 show popup alert on window close

·

,
angular 10 show popup alert before window close

Hello to all, welcome to therichpost.com. In this post, I will show you, Angular 10 show popup alert on window close.

Angular show alert before window close

Post Working:

Hi friends, In this post, I am telling you the code for open alert popup before window or tab close and for this I have used HostListener Decorator, who listens the events.

Why this post made?

I was doing some my personal practice for angular on form submission and I did this and I am sharing with you but you can use this code in many ways like on for submission, question answers applications, gaming applications. Please share your views on this.

Angular 16 came and for basics understanding please check the below tow links:


Here is the code snippet for Angular 10 show popup alert on window close:

1. Here is the code snippet and I have used that into my src/app/app.component.ts file to detect the window or tab close events:

...
import { HostListener } from '@angular/core';
export class AppComponent {
  ..
  @HostListener('window:beforeunload', ['$event'])
  beforeunloadHandler(event:any) {
    return false;

    //I have used return false but you can your other functions or any query or condition
  }
}

This is it friends and if you have any kind of working doubt then please check above video once or have any kind related to this post then do comment below.

Jassa

Thanks

Comments

7 responses to “Angular 10 show popup alert on window close”

  1. Ganeshkumar Avatar
    Ganeshkumar

    While reloading this event triggers any solution for this

  2. Ajay Malhotra Avatar

    I will make new post on this and update you, thanks.

  3. Lalit Avatar
    Lalit

    How to give popup when starting a project

  4. Ajay Malhotra Avatar

    This is simple, you can use bootstrap modal to do this.
    Thanks.

  5. ovesh kazi Avatar
    ovesh kazi

    hii can u plz make a whatsapp group for if we have any issue or any query so we connect anytime with u?

  6. siva Avatar
    siva

    Hi
    I used same function which you given, in my case i need to show my customized popup not browser default popup .

    how can i implement it ,please help me.
    any response for this is very helpful for me.