The code below works on any browser actually. This website is also an Angular app. This code is part of a component. Again it works when I close the browser or close the component (Although there is no way of leaving the component unless the user closes the tab) on desktop. I tried not using beforeunload and I'm still having problems. It also seems the only way to test any solution would be to upload the changes to my website, wait, and then open the website on my phone and see if it worked. Any helpful suggestions would be great!
ngOnDestroy() {
this.onDestroy();
}
@HostListener('window:beforeunload')
onDestroy() {
this.chatService.leaveChat('User left');
this.profileService.newProfileObj.subscribe(data => {
this.chatService.updateChatListRemove(data.username);
});
}
EDIT:
It seems based off this documentation:
https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload
that chrome browser on android shouldn't be a problem. Doesn't state anything for chrome on iPhone.