当不在网站上的页面上时,没有触发前载事件

发布于 2025-01-31 20:34:18 字数 503 浏览 3 评论 0原文

我有一个事件,需要指示用户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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文