当不在网站上的页面上时,没有触发前载事件
我有一个事件,需要指示用户is_online
是否。我正在使用totronload
事件,该事件是在关闭页面时触发的,当它触发时,我将iS_ONLINE
属性放在false
它的工作 中当我直接关闭页面时,很好。但是,当我跳过浏览器中的另一个选项卡并等待几分钟,然后关闭页面时,此事件没有触发,我的用户is_online
状态仍然显示为true 。
这是相关的代码:
window.addEventListener(
"beforeunload",
async (event) => {
event.stopImmediatePropagation();
await set_user_is_online({value:false});
},
{ once: true }
);
I have an event that needs to indicate if the user is_online
or not. I'm using the beforeunload
event, which triggering when the page is closed, and when it trigger I put the is_online
property to false
Its works good when I close the page directly. However, when I skip to another tab in my browser and wait couple of minutes and then I close the page, this event didn't triggered and my user is_online
status still appears as true
.
this is the relevant code:
window.addEventListener(
"beforeunload",
async (event) => {
event.stopImmediatePropagation();
await set_user_is_online({value:false});
},
{ once: true }
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论