View Full Version : execute final code on window close
mkeefe
11-11-2004, 03:19 AM
Hello,
I am looking for a way to have a piece of code executed when the user closes the browser window.
Here is an example.
I have a management program that the user logs into. If they "logout" the user is dropped from the database, but if the user just closes the browser they stay logged in. Any idea how I might get this to work?
-matt
You could try putting a onclose="doStuffHere()" inside your body tag. Or you could chnage the session timeout time e.g. if using ASP this would end the session after 10 minutes of inactivity.
Session.Timeout = 10
CyanBlue
11-11-2004, 04:23 AM
Um... How do you actually check if the user pressed the X button to close the window??? Then, there is no way to check it, right???
mkeefe
11-11-2004, 03:06 PM
I know in other programming languages you can "capture" the close command of the window. I am just curious if it will not run because of different browser types. I will test it out and let you know.
-matt
mkeefe
11-12-2004, 05:04 AM
<SCRIPT language="JavaScript">
<!--
function loadOut()
{
window.location="http://www.yoursite.com/loadout.php?sid=235346317";
}
//-->
</SCRIPT>
<body onBeforeUnload="loadOut()">
Here is my result, it seems to work in all browsers.
Thank you everyone for your help.
EDIT: I am sorry for posting this in the Actionscript section. I originally thought it could be done in Flash.
-matt
CyanBlue
11-12-2004, 02:46 PM
Yup... That even checks the X button... Very nice... :)
PS> I'll move this thread to the HTML forum...
vBulletin® v3.7.1, Copyright ©2000-2008, Jelsoft Enterprises Ltd.