Best way to detect browser closing/navigation to other page and do logout

前端 未结 4 936
夕颜
夕颜 2021-01-02 13:52

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

4条回答
  •  悲&欢浪女
    2021-01-02 14:23

    Why not just make a very short lived session cookie that is reset with each page load, then add a tracking cookie. When the user returns you notice the tracking cookie but no session cookie. Expire the session and clear everything up at that point.

    Pop up blockers will prevent your session clean up when it blocks the onUnload window open, because this is something spammers use.

提交回复
热议问题