如何在javascript中检测浏览器关闭和重新加载按钮单击事件 [英] How to detect browser close and reload button click event in javascript

查看:68
本文介绍了如何在javascript中检测浏览器关闭和重新加载按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们遇到Tab / browser关闭用户将从应用程序注销的情况。我们能够在浏览器/ Tab关闭时注销用户,但在浏览器重新加载按钮上单击用户也会退出系统。



我们如何避免用户退出浏览器重新加载按钮点击?



我尝试了什么:



我们尝试过onbeforeunload事件,但它没有按预期工作。

We have the situation that on Tab / browser close user will logout from the application. We are able to logout user on browser / Tab close, but on browser reload button click user also get logged out of the system.

How we can avoid the user logged out from the browser reload button click?

What I have tried:

We have tried with onbeforeunload event but its not working as we expected.

推荐答案

您没有获得关闭标签或浏览器的任何特定事件,因此无法知道这些事情何时发生,浏览器如何工作不是html规范的一部分。我甚至不知道浏览器重新加载按钮是什么,它显然是您正在使用的特定浏览器的功能,您如何期望全球标准支持某个浏览器特定的内容?



停止尝试在关闭时将人员记录下来。使用非持久性cookie进行身份验证,当他们关闭浏览器时,他们的身份验证会话也会死亡,他们需要再次登录。如果你试图阻止人们多次登录,那么也停止这样做,使用像网络这样的无状态技术是不可能的。
You don't get any specific events for closing tabs or the browser so it's not possible to know when those things are happening, how the browser works is not a part of the html specification. I don't even know what a "browser reload" button is, it is obviously a function of a specific browser you are using, how do you expect something specific to one browser to be supported by a global standard?

Stop trying to log people out when they close things. Use non-persistent cookies for your authentication and when they close the browser their auth session also dies and they need to log in again. If you're trying to stop people logging in multiple times then stop doing that also, it's not possible with a stateless technology like the web.


我在Google上用标题进行了快速搜索你的问题:如何检测浏览器关闭并重新加载javascript中的按钮点击事件 - Google搜索 [ ^ ]并找到以下内容: javascript - 试图检测t浏览器关闭事件 - 堆栈溢出 [ ^ ]和 javascript - 尝试检测浏览器关闭事件 - Stack Overflow [ ^ ]和其他人......选择一个最适合你的人。
I did a quick search on Google with the title of your question: How to detect browser close and reload button click event in javascript - Google Search[^] and found the following: javascript - Trying to detect browser close event - Stack Overflow[^] and javascript - Trying to detect browser close event - Stack Overflow[^] and others ... pick one that suits you best.


这篇关于如何在javascript中检测浏览器关闭和重新加载按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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