简体   繁体   English

在不影响其他功能的情况下检测浏览器关闭或选项卡关闭

[英]Detecting Browser Close or Tab Close without Impacting other functionality

I want to invalidate the session when the user close the tab or browser in my GWT Application. 当用户关闭我的GWT应用程序中的选项卡或浏览器时,我想使会话无效。 I saw lot of threads Confirm Browser Exit in GWT but didn't get the solution which i am looking for. 我看到很多线程在GWT中确认浏览器退出,但没有得到我正在寻找的解决方案。 This should not fire when user refresh the browser(it shouldn't invalidate the session) and even it should not fire when user navigate to other screen or download any file.Any Idea? 用户刷新浏览器时不应触发(不应使会话无效),甚至当用户导航至其他屏幕或下载任何文件时也不触发。

There is no way to tell the difference between closing a window or navigating away in various ways. 没有办法说出关闭窗口或以各种方式导航之间的区别。 You may be able to get around refreshing a page issue by creating a timer on the server side to see if a user requests your page again within a certain period of time, but it's not clear what benefits you get. 通过在服务器端创建一个计时器来查看用户是否在一定时间内再次请求您的页面,您也许可以解决刷新页面问题的问题,但是尚不清楚您能获得什么好处。

From a user experience view, you should offer a Sign Out (Log out) button or something similar, so a user can clearly indicate an intent to leave your app. 从用户体验的角度来看,您应该提供一个“退出”按钮或类似的按钮,以便用户可以清楚地表明要退出您的应用的意图。 Also, you can set an inactive timeout on your session, to invalidate session after a period of inactivity. 另外,您可以在会话上设置非活动超时,以在一段时间不活动之后使会话无效。

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

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