Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Captue window.close() event

Question posted by: jimmy (Guest) on April 2nd, 2007 12:15 PM
Hi all,
I want to capture the event when the browser's close button is
clicked
in an html page.
I tried using the event.ClientX and event.ClientY property in the
body unload event, and this helps to recognise whether the close
button is clicked( also differentiates whethet refresh was clicked).
The problem arises whenever i try to close the window by resizing it
or by right clicking at the bottom of the page and then closing it.
Can anybody tell how to capture the window.close() event??

Randy Webb's Avatar
Randy Webb
Guest
n/a Posts
April 2nd, 2007
04:35 PM
#2

Re: Captue window.close() event
jimmy said the following on 4/2/2007 8:05 AM:
Quote:
Hi all,
I want to capture the event when the browser's close button is
clicked in an html page.


That depends on what you mean by "in an html page". If you are referring
to the X on the upper right corner of a PC Based browser window, then
give up now because you will ultimately fail. Searching the archives for
capturing when a window closes will show that it is a futile exercise.
Quote:
I tried using the event.ClientX and event.ClientY property in the
body unload event, and this helps to recognise whether the close
button is clicked( also differentiates whethet refresh was clicked).


I find that a difficult claim to believe. Especially considering that
the X that is required to close a page in IE7 - in tab mode - can be
anywhere other than the top right corner of the browser window.
Quote:
The problem arises whenever i try to close the window by resizing it
or by right clicking at the bottom of the page and then closing it.


Close a window by resizing it? How do you do that?
Quote:
Can anybody tell how to capture the window.close() event??


You can't. Besides, why does it matter whether I close my browser or
not? I can close your page without closing my browser.

If you have some reason to need to know when the page is closed so you
can clean up some code on the server then the browser isn't the place to
do that, the server is with Sessions.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

=?ISO-8859-1?Q?G=E9rard_Talbot?='s Avatar
=?ISO-8859-1?Q?G=E9rard_Talbot?=
Guest
n/a Posts
April 4th, 2007
01:25 AM
#3

Re: Captue window.close() event
jimmy wrote :
Quote:
Hi all,
I want to capture the event when the browser's close button is
clicked
in an html page.
I tried using the event.ClientX and event.ClientY property in the
body unload event, and this helps to recognise whether the close
button is clicked( also differentiates whethet refresh was clicked).
The problem arises whenever i try to close the window by resizing it


How do you actually close a window by resizing it?
Quote:
or by right clicking at the bottom of the page and then closing it.


What's your page url?
Quote:
Can anybody tell how to capture the window.close() event??


Why do you want to "capture" the close event? What exactly are you
trying to do? Can you provide explanations, description regarding your
webpage goals, requirements, purposes? What close event do you really
want to "capture": the webpage being unloaded or the window being closed?
In which way dealing with the closing of the window or unloading of a
webpage is actually contributing to the content for the users or
contributing to the experience of the users?

Gérard
--
Using Web Standards in your Web Pages (Updated Dec. 2006)
http://developer.mozilla.org/en/doc..._your_Web_Pages

jimmy's Avatar
jimmy
Guest
n/a Posts
April 4th, 2007
04:35 AM
#4

Re: Captue window.close() event
Quote:
How do you actually close a window by resizing it?

I meant after resizing it...
Quote:
Why do you want to "capture" the close event? What exactly are you
trying to do? Can you provide explanations, description regarding your
webpage goals, requirements, purposes? What close event do you really
want to "capture": the webpage being unloaded or the window being closed?
In which way dealing with the closing of the window or unloading of a
webpage is actually contributing to the content for the users or
contributing to the experience of the users?
>

Problem is that whenver te user changes the data on the screen and
leaves it without saving the data, I prompt user to save the data by
calling a function on the body onunload event.

So in the body unload event i call a function which does the following
thing:-
************************************************** **
if (event.clientY < 0 && event.clientX 500)
{
//don't ask the user to save the data


}


************************************************** *
Event here refers to the click and
event.clientY < 0 ensures that the button wasn't clicked in the
body and event.clientX >500 ensures that the user is not prompted to
save
when the refresh button is clicked, bcoz the page would unload in
that
event also.
I know that event.clientX >500 won't work when the screen size or the
browser's size is small...that is one of the problems i m facing
besides the user closing the window using Alt+F4 or by right clicking
at the bottom and then closing it..


terriblecow's Avatar
terriblecow
Guest
n/a Posts
April 12th, 2007
08:05 PM
#5

Re: Captue window.close() event

I think there is a way to do it. Just open your gmail account and
compose a new message. If you navigate away from the page or close
the browser there is a popup to save changes.

I think this is excatly what jimmy was looking for. And quite frankly
I'm looking for the same thing. I'm going to be looking through the
google code to see if I can figure out how they interrupt/catch the
close event.

If anyone has any other comments they are quite welcome.

Thanks!


Randy Webb's Avatar
Randy Webb
Guest
n/a Posts
April 12th, 2007
08:45 PM
#6

Re: Captue window.close() event
terriblecow said the following on 4/12/2007 3:55 PM:
Quote:
I think there is a way to do it.


A way to do what?
Quote:
Just open your gmail account and compose a new message.


What gmail account?
Quote:
If you navigate away from the page or close
the browser there is a popup to save changes.


onbeforeunload, and as I have already said, it is unreliable at best.
Quote:
I think this is excatly what jimmy was looking for. And quite frankly
I'm looking for the same thing. I'm going to be looking through the
google code to see if I can figure out how they interrupt/catch the
close event.
>
If anyone has any other comments they are quite welcome.


I have one. Try quoting what you are replying to.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

 
Not the answer you were looking for? Post your question . . .
189,872 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors