Page 1 of 1

closing window

Posted: Thu May 01, 2003 5:44 am
by Guy
is there a way to know if the client has closed the window I opened for him with the X at the top right corner?
I have a close button because I need to do something on close so if the user closed the window with the X button
I'll still catch it.
Thanks
Guy

Posted: Thu May 01, 2003 5:46 am
by []InTeR[]
Here you are:

Code: Select all

<BODY onOnload="javascript:alert('user closed')">

Posted: Thu May 01, 2003 10:17 am
by Wayne
That should be :

Code: Select all

<BODY onUnLoad="javascript:alert('user closed')">

not quite yet

Posted: Thu May 01, 2003 12:56 pm
by phpScott
this is a very simple script that will work

the JavaScript event handler is onUnLoad

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script script language="JavaScript">
function ThewindowIsBeingClosed()
&#123; window.open("http://cnn.com");
&#125;
</script>
</head>

<body onunload=ThewindowIsBeingClosed()>

</body>
</html>
do what ever you want in the function.

phpScott

ps. It works for IE but not NetScape 7 at least.
If the client closes the browser this script doen't fire but if they close the tab it will.

Posted: Thu May 01, 2003 7:27 pm
by phice
Sound's like someone's working for a popup/under company. ;)

Posted: Fri May 02, 2003 2:03 am
by []InTeR[]
Sorry Typo
OnUnLoad
[]InTeR[] wrote:Here you are:

Code: Select all

<BODY onUnload="javascript:alert('user closed')">
[/b]