JavaScript上的我们是否有可能在事件上检测到该事件之前的固定/卸载,如果刷新或离开?
//这似乎是一个重复的问题,但是我发现的所有问题都是旧的,并且想知道最新浏览器要求中是否有任何新功能
:确定用户是否刷新或重新加载了页面 在事件中,“ 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
然后记录用户与您的页面进行交互的最后一次,并且仅在下一个打开的网络呼叫,如果它足够接近上次交互时间(“闻起来像重新加载”)。您还可以利用
sessionstorage
是每个标签的事实,在刷新选项卡时将保留。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.