简体   繁体   English

我们可以不使用“ onunload”来捕获相同的浏览器关闭事件吗?

[英]Can we capture the same browser closing event without using “onunload”

Actually using the window.close , we can control whether browser is closed or not, but it works only for pop-ups created by the browser. 实际上使用window.close ,我们可以控制浏览器是否关闭,但是它仅适用于浏览器创建的弹出窗口。

So, are there any ways to listen to the closing event of the browser without using onunload ? 因此,有什么方法可以在不使用onunload情况下监听浏览器的关闭事件? Because we don't want things to be executed when back , refresh or forward actions occur. 因为我们不希望在back时执行任何事情,所以会发生刷新转发动作。

Please also reply if you know specifics regarding Firefox. 如果您知道有关Firefox的详细信息,也请回复。

Thanks in advance! 提前致谢!

You are trying to manipulate the EXPECTED behaviour of the browser, essentially taking away people's ability to navigate. 您正在尝试操纵浏览器的“预期”行为,从本质上剥夺了人们的导航能力。 Fortunately browser developers were smart enough to disallow this - so the answer is NO. 幸运的是,浏览器开发人员足够聪明,不允许这样做-因此答案是否定的。

我还想以与onunload不同的方式关闭浏览器/选项卡,因为在这种情况下我想执行一些验证,但不是页面中存在的所有onunload可能性,这对我来说是一个有效的用例。

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

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