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

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

问题描述

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

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.

我目前通过挂钩 onUnload() 事件并打开一个指向注销 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.

推荐答案

看起来 GWT 确实有一个专门针对此的事件.

Looks like GWT does have an event for exactly this.

关闭事件.

看起来你需要实现一个 ClosingHandler

Looks like you need to implement a ClosingHandler

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

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