JavaScript上的我们是否有可能在事件上检测到该事件之前的固定/卸载,如果刷新或离开?

发布于 2025-01-21 07:46:19 字数 104 浏览 1 评论 0原文

//这似乎是一个重复的问题,但是我发现的所有问题都是旧的,并且想知道最新浏览器要求中是否有任何新功能

:确定用户是否刷新或重新加载了页面 在事件中,“ nunload”或“卸载”。

// This might seem to be a duplicate question, but all the questions I have found were old and was wondering if there is any new functionality available in the latest browsers

Requirement: Identify if the user has refreshed or reloaded the page
on the event "beforeunload" or "unload".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

病毒体 2025-01-28 07:46:19

我有一个用户酶,如果用户正在刷新页面,则需要完成。这是一个Netwok调用,因此,如果用户关闭了选项卡,则不想执行网络调用。

然后记录用户与您的页面进行交互的最后一次,并且仅在下一个打开的网络呼叫,如果它足够接近上次交互时间(“闻起来像重新加载”)。您还可以利用sessionstorage是每个标签的事实,在刷新选项卡时将保留。

i have a usecase that needs to be done if the user is refreshing the page. it is a netwok call and hence dont want to the network call to be executed if the user have closed the tab.

Then record the last time the user interacted with your page, and only do that network call on the next open, if it is close enough to the last interaction time ("smells like a reload"). You can also take advantage of the fact that sessionStorage is per-tab, and will be retained when refreshing the tab.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文