closing window

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Guy
Forum Commoner
Posts: 53
Joined: Sun Jan 12, 2003 3:34 am

closing window

Post 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
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Here you are:

Code: Select all

<BODY onOnload="javascript:alert('user closed')">
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

That should be :

Code: Select all

<BODY onUnLoad="javascript:alert('user closed')">
Last edited by Wayne on Wed May 14, 2003 5:31 am, edited 1 time in total.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

not quite yet

Post 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.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Sound's like someone's working for a popup/under company. ;)
Image Image
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Sorry Typo
OnUnLoad
[]InTeR[] wrote:Here you are:

Code: Select all

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