Connecting Tech Pros Worldwide Forums | Help | Site Map

Detecting user closing window X

Kiran
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi all,

Can anybody let me know how to detect when my user clicks the X button
on the window. I used unload event it did not work(on IE). My web page
is a .asp page which reloads itself when navigating on the site. Now
whenever the user clicks any links on the page the unload event is
triggered which is not what I want. I only want to detect when user
clicks the X button and not when the URL changes.

code i used:
<body onunload="alert('leaving window');">

Basically this alert window is triggered everytime the URL changes and
not just when the window closes(which is what i want).
Appreciate your reply.
Kiran


Randy Webb
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Detecting user closing window X


Kiran wrote:[color=blue]
> Hi all,
>
> Can anybody let me know how to detect when my user clicks the X button
> on the window.[/color]

You can't.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Fred Oz
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Detecting user closing window X


Kiran wrote:[color=blue]
> Hi all,
>
> Can anybody let me know how to detect when my user clicks the X button
> on the window.[/color]
[...]

The web is "stateless". You never know whether you users are still
there or not. Don't try to detect if they are still looking at your
page, design your system so it isn't necessary. There is no reliable
way of knowing whether they are or not.

There are lots of ways of closing a window such that the browser never
gets to know it's about to be killed (Windows task manager, UNIX
kill -9, Mac "force quit application" do dad, turn off power, etc.).

Nothing for it but to learn to live with it. :-)


--
Fred
Closed Thread