Hello, I'm working on a logout feature in my application and for that, I need to check if user has leaved my application and so call an Http Request to finish the API session. I've searched a lot on the topic and couldn't get too much. What I'm currently doing is using @HostListener decorator to listen a "beforeunload" event, but yet, that is not the properly functionality we wanted. Take a look:
@HostListener('window:beforeunload', ['$event'])
beforeUnloadHandler(event: BeforeUnloadEvent) {
// *trying to stop showing the popup;
// event.preventDefault();
// event.stopImmediatePropagation();
// calling my logout function()
this.myLogoutFunction(event);
return false;
}
the first problem using this method is that it is being called when the page is reload and that cannot happen. It should be called just and only when either the tab or browser is closed. The second problem is a popup asking "You sure want to leave site?". We do not want to be asked, but I didn't figured out how to disable this popup.
this is quite a big problem to me and I'm not getting to solve it. Very very thank you if someone could help me 🙂