0

In my angular application I want to display a message when the user tries to reload or leave the browser without saving his changes or when a background process is still running (according to a flag in my code).

However, The only option I found is to enable the default browser alert, with its default message: "Changes you made may not be saved."

I cannot find any way to override this popup.

user2717436
  • 775
  • 1
  • 10
  • 23
  • Does this answer your question? [How to customize the message "Changes you made may not be saved." for window.onbeforeunload?](https://stackoverflow.com/questions/40570164/how-to-customize-the-message-changes-you-made-may-not-be-saved-for-window-onb) – Giannis Mar 08 '21 at 10:46

1 Answers1

0

you can try bellow code:

@Component({ 
  selector: 'app-root',
  ..
)}
class AppComponent{
  @HostListener('window:beforeunload', ['$event'])
  doSomething($event) {
    if(this.hasChanges) $event.returnValue='Your data will be lost!';
  }
Aref Zamani
  • 2,023
  • 2
  • 20
  • 40