Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

End Session on Window Close 1

Status
Not open for further replies.

lucidity23

Programmer
Feb 14, 2001
99
US
Ok...I have found only limited info on this...

I have a session that is set with a time limit. However I would like to close out the session if the browser window is closed.

Wheteher it be in ASP, Java, Javascripting, or whatever. I can use or learn whatever I ened to. I just want to add this feature to my site cuz it will allow me to do a lot more with the session knowing they will end if the person leaves.

Thanks!!!
- carpe diem -
 
I can only speak from a JavaScript / ASP perspective and say that it's a little tricky. The only event handlers in JavaScript that would even come close to your solution would be these.

onUnload
onBlur


Here are the problems with those.

onUnload
This event handler will fire every time the page changes in the browser window. Refresh and navigation will fire that event handler. So unless you're talking about a window that has no page links or no refresh options, this won't work for you.

onBlur
This is probably the closer one to your needs. The only problem here is that this event handler will get fired if the visitor minimizes the window. If you're willing to close the session if the visitor minimizes the window, this is your best bet.

<html>
<head>
<script Language=&quot;JavaScript&quot;>
function endSession() {
window.location.href=&quot;somepage.asp&quot;
}
</script>
</head>
<body onBlur=&quot;endSession();&quot;>
</body>
</html>


Then in somepage.asp end the session with Session.Abandon

Hope this helps.

ToddWW :)
 
That is helpful...

I use Frames and one of those frames has nothing in it...

I could use that...but then it would fire if someone refreshed...

I may try that second option...

Is there a way to detect if the windo was minimized?
- carpe diem -
 
No, and that's where you're stuck. Unfortunately, and dissapointedly, JavaScript does not segregate the minimize and close methods into seperate event handlers. There treated identically and both fire the onBlur event handler.

I've seen some people do some tricks to determine if a window is closed or not, but that was with two windows on the desktop.

In other words, they would have on onBlur event handler in the sub window that would fire a function in the main / parent window. That window would run a conditional test to see if the sub window was valid. If it's there, even if it was minimized, it would return true. But if it was closed, it would return false. Then the function in the main window would continue processing based on the fact that the sub window was closed.

But I have no idea how you could do this with just one window, and I don't think it's possible.

ToddWW :)
 
Looks like I got a challenge for myself...

How to do all the magic and maintain having only 1 window...

joy... :)

Thanks for the help Todd...I will let ya know if I find out anything useful...
- carpe diem -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top