PDA

View Full Version : How to trace browser close


gajra
10-24-2002, 09:17 AM
For my web application i need to know, when the user closes the browser i need to do some activities.Can anybody help in that to trap that event for my appln.

raf
10-24-2002, 09:40 AM
depends on what you want to do. when the browser closes you can't do anything on the users box.

ASP has a session-object. If you place a global.asa into your applications root, you can use the session_onend sub to perform action (on the server side) when the browser is closed, OR when the application timeouts)

more info about global.asa
http://www.codingforums.com/showthread.php?s=&threadid=5688&highlight=global.asa

or in one of the 15 other posts the search turned up.

gajra
10-24-2002, 11:44 AM
When the browser is closed i want to write some information onto a file which exists into my server.

when i use browser's close button session_end event is not firing pls help more info...I am working in .net

Roy Sinclair
10-24-2002, 03:12 PM
There is no way to detect the difference between when the user closes the browser window, navigates to another page or even just "refreshes" the current page.

You need to think of another way to accomplish the needed actions.

glenngv
10-25-2002, 08:50 AM
still possible, at least in IE :)


<html>
<head>
<title>Detecting Closing of Window in IE</title>
<script language="javascript">
function doUnload()
{
if ((window.event.clientX < 0) && (window.event.clientY < 0))
{
alert("The window is closed...");
//do some stuff here like:
//window.open("properLogout.asp","","width=10,height=10,left=8000,top=6000");//hide window
//or silent logout
//logout = new Image();
//logout.src = "properLogout.asp";
}
}
</script>
</head>
<body onunload="doUnload()">
<h3>Detecting Closing of Window in IE</h3>
Do these ways below and see the difference:<br>
1. Try to refresh the page.<br>
2. Try to type any URL in the address bar.<br>
3. Click a <a href="http://www.google.com/">link</a>.<br>
4. Try to close this window by clicking X button of this window.
</body>
</html>

Keltoi
10-25-2002, 02:46 PM
I've done a similar process b4 to what you're asking, and it should be cross browser as the idea is very simple:

Create a button to close the browser.
on click send the user to a process page where you can perform whatever task you require automatically. Then place your script to actually close the window.

Of course this only works if the user presses your button and doesn't use the browser facilities to close the window.

whammy
10-26-2002, 04:45 AM
I think that's what he's trying to avoid.