Home Angular 10 Angular 10 show popup alert on window close

Angular 10 show popup alert on window close

by therichpost
Published: Updated: 7 comments
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

You may also like

7 comments

Ganeshkumar September 20, 2021 - 5:22 am

While reloading this event triggers any solution for this

Reply
Ajay Malhotra September 20, 2021 - 5:29 am

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

Reply
Lalit September 22, 2021 - 7:14 am

How to give popup when starting a project

Reply
Ajay Malhotra September 22, 2021 - 8:05 am

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

Reply
ovesh kazi December 7, 2021 - 7:23 am

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

Reply
Ajay Malhotra December 7, 2021 - 7:35 am

yes sure and here you join that group:
https://chat.whatsapp.com/HHvVqmqMIrd7kqpstaNAuL

Reply
siva October 7, 2022 - 11:17 am

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.

Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.