在浏览器关闭时检测刷新浏览器以进行卸载/ beforeunload [英] detect refresh browser for unload/beforeunload when browser closed

查看:248
本文介绍了在浏览器关闭时检测刷新浏览器以进行卸载/ beforeunload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上是我上一次问题的延续。我仍然面临问题,因为当我刷新浏览器时,卸载或者beforeunload也会触发,我只想在浏览器关闭时使用它们。刚想到我使用window.outerHeight或window.innerHeight,但仍然无法弄清楚如何做到这一点。有什么建议/片段吗?提前致谢。

This is actually continuation of my last question. I still face problem since when i refresh browser, either unload or beforeunload also fired which I only want them when browser closed. Just crossed on my mind to use window.outerHeight or window.innerHeight but still can't figure out how to do this. Any suggestion/snippet? Thanks in advance.

推荐答案

据我所知,无法检测浏览器与浏览器刷新分开关闭,因为浏览器不提供包含该信息的网页(窗口)。就你的页面和它的Javascript代码而言,两者是同一个。

As far as I know it is impossible to detect a browser close separately from a browser refresh, because the browser does not provide the webpage (window) with that information. As far as your page and its Javascript code are concerned, the two are one and the same.

因为它是你需要的浏览器信息,所以获得它的唯一方法是使用可以访问该信息的东西,即。一个浏览器插件。但是,您需要为每个浏览器创建一个插件,并让每个用户安装它。因为我非常怀疑你会发现这是值得的,你问题的真正答案(尽管可能令人沮丧)是:停止尝试检测刷新与关闭并继续前进。

Since it's browser info that you need, the only way to get it is to use something that has access to that info, ie. a browser plug-in. But then you'll need to make a plug-in for each browser, and get every user to install it. Since I highly doubt you'll find this worthwhile, the real answer to your question (as frustrating as it may be) is: stop trying to detect refreshes vs. closes and move on.

这篇关于在浏览器关闭时检测刷新浏览器以进行卸载/ beforeunload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆