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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capturing browser exit 2

Status
Not open for further replies.

Gamera99

Programmer
May 17, 2001
59
JP
I am writing an intranet app in Interdev 6 with an Oracle 8i backend. I have a DBA page which shows all current users. I write them into an oracle table when the users' individual session_onstart events fire, and I remove them when the session_onend event fires (unfortunately this is usually after the 20 minute timeout).
Does anyone know how to capture a browser exit event (when a user clicks the X in the upper right hand corner) or other way of closing a browser? I don't want to rely on the session timeout but I can't figure out how to capture the moment a user closes the browser.
Thanks to anyone who can help.
 
I know how it is in JavaScript (Client side script) - it works also in VBScript:

...
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function leave() {
//here you can make the logging you need
}
</SCRIPT>

<BODY onUnload=&quot;leave()&quot;>
....

Hope this helps,s-) Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
I'm not a javascript expert - can I just say the following in the script portion?

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function leave() {
Session.Abandon;
}
</SCRIPT>

Thanks for your help

 
No, you can't because this is client side script.
The session object exists only on the ASP server.

You can make something like submitting hidden variabile from a form:
1.
function leave()
{
ExitForm.Submit()
//or document.forms(&quot;ExitForm&quot;).Submit()
}
2.
inside the <BODY> tag, no matter where you put
<FORM NAME=&quot;ExitForm&quot; action=&quot;Logger.asp&quot; method=&quot;POST&quot;>
<INPUT type=&quot;hidden&quot; name=&quot;exit&quot; value=&quot;true&quot;>
<INPUT type=&quot;hidden&quot; name=&quot;nextprogram&quot; value=&quot;TheNextProgram.asp&quot;>
</FORM>

3.logger.asp should make the log you want from the Request.ServerVariabiles or from other source and optionally run the TheNextProgram.asp

There may be other ways of doing this, this is the first one that came to my mind.

Hope this helps you,s-) Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
I have been trying to find a way to capture the browser window itself closing. I have several ASP pages that load, unload, reload, etc. Running a function on the Body_onUnload event would be good if I wasn't using so many different pages. The problem is that we have a logoff button which is used to log users off of a server (other than the web server), but users could just use the 'X' button to close IE...but this leaves them logged on to the other server. Any suggestions?
 
Guys,
i'm afraid, there's some trap in using this event.

It may fire when:
a) Closing the current browser window
b) Navigating to another location by entering a new address or selecting a Favorite
c) Clicking the Back, Forward, Refresh, or Home button

Then how you suppose to determine that user really finished his session???
 
Hello,
Check also what I have posted in thread333-95471.
Hope this helps.
D.
 
Thanks, but the problem here is that if I put code into the BODY tag of a document, it will fire each time the page unloads. Users navigate to several different pages in my web-based application, and the Unload event will fire each time they navigate to a page (assuming I put the code in the Unload event of each page). I don't want this to fire each time each page unloads...I only want it to fire when the BROWSER WINDOW closes.

Any suggestions?
Thanks.
 
RJoub here is a lame idea but it might work;
You could have the default.asp construct 2 frames (one frame can be at the top or bottom and be very small - this frame page will always be resident no matter how the main section pages are changing constantly).
Then have the <body unload...> tag in the resident frame page which will detect the unloading of the entire thing, irrespective of the main frame pages.
Hope this made sense.
 
Thanks...it's not a lame idea. I never thought of that. I will give it a shot.

Rich
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top