[英]window:beforeunload works on chrome browser but not chrome mobile browser. Angular 6
The code below works on any browser actually. 以下代码实际上可在任何浏览器上使用。 This website is also an Angular app.
该网站也是Angular应用程序。 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.
我尝试不使用beforeunload,但仍然遇到问题。 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 https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload
that chrome browser on android shouldn't be a problem. android上的chrome浏览器应该没问题。 Doesn't state anything for chrome on iPhone.
对于iPhone上的Chrome,没有任何说明。
Solved this about 6-7 weeks ago. 大约在6-7周前解决了此问题。 Instead of using window:beforeunload as a trigger to notify the backend (node.js w/ socket.io), I simply only use the backend.
与其使用window:beforeunload作为触发来通知后端(node.js w / socket.io)的触发器,我仅使用后端。 Doesn't make sense to have the front end notify the backend when a user has disconnected.
当用户断开连接时,让前端通知后端是没有意义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.