检测浏览器关闭/导航到其他页面并注销的最佳方式 [英] Best way to detect browser closing/navigation to other page and do logout

查看:145
本文介绍了检测浏览器关闭/导航到其他页面并注销的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GWT中编写应用程序,我需要检测用户何时离开我的应用程序或关闭浏览器窗口(onUnload事件)并执行注销(会话失效和其他一些清理任务)。注销操作由一个servlet执行。

我正在通过挂钩onUnload()事件并打开一个指向注销servlet的新窗口来做到这一点。

有没有更好的方法来做到这一点?欢迎您提出任何其他建议。

解决方案

看起来GWT确实有这样的事件。

ClosingEvent



看起来您需要实施 ClosingHandler

I am writing an application in GWT and I need to detect when a user navigates away from my application or when he closes the browser window (onUnload event) and do a logout (session invalidation and few other cleanup tasks). The logout action is performed by a servlet.

I am currently doing this by hooking into the onUnload() event and opening a new window pointed to the logout servlet.

Is there a better way to do this? Any other suggestions are welcome.

解决方案

Looks like GWT does have an event for exactly this.

ClosingEvent.

Looks like you need to implement a ClosingHandler

这篇关于检测浏览器关闭/导航到其他页面并注销的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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