Invalidating session on browser close

I need to find a way to invalidate the session when the user closes the browser.We are currently calling a servlet from a javascript function that is called via the onunload function.

invalidating session on browser close-21

Invalidating session on browser close www goldendating info

But, the function is also called when the user refreshes the page.

I have also considered using the interface Disposable Bean but its dispose() method is also called when the browser is refreshed.

Our web app using ICEfaces is displayed via a popup window in which the parent window is always present. Actually I have 3 scenarios to close session: 1.- A user close session using a button. 2.- A user close the browser, so you call before Close using javascript 3.- The session timeout expiry. Right now I'm not invalidating the session, I detect the browser is closed and I eliminate the session from the context (previosly I added), so I have a control over the sessions.

We are seeing the user session timeout prematurely if we do not kill the session when the user closes the popup window. In this case you can't do anything against a database or whatever because once the session expiry is like you are not in the web application, so resources are open... My problem is when there is a session expiry, in that moment I can't do anything.

No way is guaranteed to work (across all major browsers and their different versions).

Your connection could be dropped, or power go down which would make any 'on Close' event unreliable.

While this approach will work in a simple scenario a couple of points should be addressed before you begin implementation. Otherwise maintenance of hundreds or thousands of connections via polling will do more harm than good.

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

This all make sense, however, now we have a requirement that the user, when they click logout, should be signed out completely without having to close the browser.

Tags: , ,