Capture click event of the "x" button on the browser window

G

Guest

Hi,

Need help on the following issue.

We need to clean up some session specific backend resource when a user ends
his session. We have a "Logoff" button on the pages that handles that. But
the problem is that sometimes the user still closing their browser window by
clicking on the "x" button of the window. This is quite a problem for us
because it will leave unreleased resource on the server for an unpredictable
period of time, depending the timeout setting on our client's web app.

Simply putting the logic in the window.onclose JavaScript wouldn't do the
job unless there is a way we can test and tell where the caller is from.
Because the clean-up work needed are different when exits from "x" than exits
from code.

Therefore, what I think we need is either an event handler that traps just
the "x" click event; or, in the window.onclose JavaScript, a way to test the
caller.

Can someone please help?

Thanks in advance!!!

Feng
 
S

Scott M.

The only way to do it is with the onClose event handler of the window
object.

You could include in that event handler a form.submit() of an embedded form
that contains just one hidden form field that has a value of the sessionID.
So, when a user closes their browser, their session ID is passed to a
specific page that takes that value in and ends the session corresponding to
that session ID.

Be aware though, that users that correctly click your logout button would
still cause this code to run when they close their browser.

Most sites take care of this scenario by simply decreasing the
sessionTimeout to a value of 5 minutes or so.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top