用户关闭选项卡时注销 [英] Logout when the user close the tab

查看:58
本文介绍了用户关闭选项卡时注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Django网站上,我想在关闭标签页或浏览器时自动从网站注销。我的意思是当我通过关闭选项卡而不是使用注销按钮关闭网站时,再次输入URL后,我想看到用户已经从网站注销以强制用户再次输入用户名和密码。

On my Django site, I want to logout from the site automatically when I close the tab or browser. I mean when I close the site by closing the tab instead of using logout button, after entering the URL again, I want to see that the user has already logged out from the site to force the user to enter username and password again.

有没有办法处理关闭JQuery中的选项卡?

Is there a way to handle closing the tab in JQuery?

提前谢谢。

编辑:onunload& onbeforeunload事件导致在重新加载页面时注销用户。

onunload & onbeforeunload events cause to logout the user when also reloading the page.

推荐答案

我刚碰到这个。在你的Django settings.py文件中,你可以添加标志:

I just ran into this. In your Django settings.py file, you can add the flag:


SESSION_EXPIRE_AT_BROWSER_CLOSE = True

SESSION_EXPIRE_AT_BROWSER_CLOSE = True

这将在浏览器关闭时将用户注销。 请注意,如果还有其他标签或窗口仍然打开,用户将保持登录状态(浏览器必须完全关闭)。

This will log the user out when the browser is closed. Note that the user will remain logged in if there are other tabs or windows still open (the browser must be completely closed).

这篇关于用户关闭选项卡时注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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