简体   繁体   English

如何区分浏览器关闭和选项卡关闭

[英]How to Differentiate between browser close and tab close

I want my application to execute some code when the browser is closed.我希望我的应用程序在浏览器关闭时执行一些代码。 My problem is beforeunload event that is called on both the browser close button and tab close.我的问题是在浏览器关闭按钮和选项卡关闭时调用的 beforeunload 事件。 I don't need that code to be executed on tab close.我不需要在选项卡关闭时执行该代码。 Is there any way that we can execute that code on browser close not on tab close?有什么办法可以在浏览器关闭时而不是在选项卡关闭时执行该代码?

I have tried beforeunload event that is calling on browser close and tab close.我已经尝试过调用浏览器关闭和选项卡关闭的 beforeunload 事件。 I need to separate these close calls so that the same code shouldn't be executed on for browser close and tab close.我需要将这些关闭调用分开,这样就不会为浏览器关闭和选项卡关闭执行相同的代码。

Unfortunately it is not possible to differentiate between these events.不幸的是,无法区分这些事件。 Refer to this thread Detect browser or tab closing参考这个线程Detect browser or tab closing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM