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

Saravanan M picture Saravanan M · May 20, 2009 · Viewed 10.3k times · Source

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.

Answer

Carnell picture Carnell · May 20, 2009

Looks like GWT does have an event for exactly this.

ClosingEvent.

Looks like you need to implement a ClosingHandler