Detect browser or tab closing(检测浏览器或标签页关闭)
问题描述
是否有任何跨浏览器 JavaScript/jQuery 代码来检测浏览器或浏览器选项卡是否正在关闭,但不是由于单击了链接?
Is there any cross-browser JavaScript/jQuery code to detect if the browser or a browser tab is being closed, but not due to a link being clicked?
推荐答案
如果我理解正确,您想知道选项卡/窗口何时有效关闭.好吧,AFAIK 在 Javascript
中检测这种东西的唯一方法是 onunload
&onbeforeunload
事件.
If I get you correctly, you want to know when a tab/window is effectively closed. Well, AFAIK the only way in Javascript
to detect that kind of stuffs are onunload
& onbeforeunload
events.
不幸的是(或幸运的是?),当您通过 link
或浏览器的后退按钮离开网站时,也会触发这些事件.所以这是我能给出的最好答案,我认为你不能在Javascript中原生检测到纯 close
.如果我在这里错了,请纠正我.
Unfortunately (or fortunately?), those events are also fired when you leave a site over a link
or your browsers back button. So this is the best answer I can give, I don't think you can natively detect a pure close
in Javascript. Correct me if I'm wrong here.
这篇关于检测浏览器或标签页关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检测浏览器或标签页关闭


- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01