简体   繁体   English

window:beforeunload适用于chrome浏览器,但不适用于chrome移动浏览器。 角度6

[英]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.

相关问题 window.print 在移动 chrome 浏览器中不起作用 - window.print is not working in mobile chrome browser 在浏览器窗口中居中,可在野生动物园中使用,但在Firefox或Chrome中无法使用 - centering in browser window, works in safari but not firefox or chrome 移动 (Chrome) 浏览器通知 - Mobile (Chrome) browser notifications window.onunload 在 Chrome 浏览器中无法正常工作。 谁能帮我? - window.onunload is not working properly in Chrome browser. Can any one help me? 不是页面顶部,但 window.scrollY 在 chrome 移动浏览器上等于 0 - Not a top of the page but window.scrollY equals 0 on chrome mobile browser 区分Android Chrome和库存浏览器。 Stock浏览器的用户代理包含'Chrome' - Distinguish Android Chrome from stock browser. Stock browser's user agent contains 'Chrome' Chrome浏览器窗口。showModal对话框 - Chrome browser window.showModaldialog 打开一个没有Chrome的小型浏览器窗口 - Opening a tiny browser window with no chrome 脚本仅适用于 Chrome 和 Firefox 桌面,不适用于 Safari 和任何移动浏览器 - Script works only on Chrome and Firefox Desktop, and not works on Safari and any mobile browser 在Chrome移动浏览器上,keypress / keyup不起作用 - keypress/keyup is not working on chrome mobile browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM