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

Detecting when the user leaves

Status
Not open for further replies.

Custom24

Programmer
Nov 27, 2001
591
GB
Hello
I am constructing an web app with active server pages, and I wanted to detect when the user leaves my site, either by closing down their web browser or navigating to another site.

I thought that the best way would be to implement client side script to fire on window_onunload, which would open another window with the location of my cleanup page. This would then contain client script to close down as soon as it was rendered, so that it did not annoy the user.

Unfortunately, the window_onunload event seems to fire on the document level, rather than the window level, with the result that every time they move to another page within my site, it performs my cleanup code.

If I can trap just the browser close, I'd be happy. If I could detect when they navigate to a site outside of mine, that would be better still

Any ideas?

This is the kind of code I've been using so far client side

sub window_onunload()
window.open "cleanup.aspx"
end sub

Thanks
Mark
 
do this via server side with the global.asa
in the
sub Session_OnEnd
create a connection to a DB
insert a variable with the time like
varTimeEnd = Date
end sub

This will run then when the user ends the session

admin@onpntwebdesigns.com
 
Nope - session_onend only fires when the session times out - if the user just closes their browser or navigates to another site, then I have to wait for the time out, which is undesirable.

I want to manually end the session server side in my cleanup.aspx using session.abandon (also works in asp as well as aspx). But to get this page to load, I need to implement the client side code and this is my problem

Thanks
Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top