-1

I want to save some data before unload the browser. but i want to do that after conformation if they press reload button means i want to save something, if they press stay here means want to stay same page. how to do this in angular 7.

Manihtraa
  • 968
  • 3
  • 12
  • 28

1 Answers1

0

I believe your question is answered in this post where the @HostListener is used to listen for the window:beforeunload event which receives a callback before the window unloads.

The version I used from the provided post is as follows

@Component({ 
  selector: 'my-selector'
)}
class MyComponent {
  @HostListener('window:beforeunload')
  beforeUnload() {
    // ...
  }
}

All credit goes to Günter Zöchbauer

navybofus
  • 59
  • 9