检测浏览器或制表符关闭 [英] 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.
不幸的是(或者幸运的是?),当您将网站放在网站上时,这些事件也会被触发链接
或您的浏览器后退按钮。所以这是我能给出的最佳答案,我不认为你可以在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.
这篇关于检测浏览器或制表符关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!