How can we detect when user closes browser ?

0
232
You can listen to the unload or beforeunload events like this:

export class AppComponent {
  @HostListener('window:unload', [ '$event' ])
  unloadHandler(event) {
    // ...
  }

  @HostListener('window:beforeunload', [ '$event' ])
  beforeUnloadHandler(event) {
    // ...
  }
}

See also

Detect browser or tab closing
https://developer.mozilla.org/de/docs/Web/Events/unload

LEAVE A REPLY

Please enter your comment!
Please enter your name here