Browser's close button

J

jimmy

Hi all,
I want to capture the event when the browser's close button is clicked
in a jsp.
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??
 
J

Jukka K. Korpela

Scripsit jimmy:
I want to capture the event when the browser's close button is clicked
in a jsp.

"In a jsp"?

What do you _really_ want to do? Have you considered the fact that a browser
can be closed in different ways, which need to involve any "close button".

As usual, a URL would illustrate the real problem, but ignore this if you
don't really want to get help
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.

So you _do_ know that capturing the close button event isn't enough. Why did
you ask about _it_, then?
Can anybody tell how to capture the window.close() event??

You might find better help with that in comp.lang.javascript. But are you
sure _that_ is your _real_ problem?
 
J

jimmy

1.consider an html in place of jsp...that really doesn't matter..
2. What i've done is that i check the coordinates of the browser for
an event in the body unload method.
If the coordinates match to those of the close button, it confirms
the window closing event by closing the browser.
So real problem arises when i resize the window which shifts the
coordinates of the browser's window and thus failing my logic.That's
why i want to capture the window.close() event and then proceed
accordingly.
 
D

Dan

1.consider an html in place of jsp...that really doesn't matter..

HTML can't capture and react to any events; it's a markup language,
not a programming language.
2. What i've done is that i check the coordinates of the browser for
an event in the body unload method.
If the coordinates match to those of the close button, it confirms
the window closing event by closing the browser.

How exactly do you claim to know the exact coordinates of the "close
button" for every possible browser and platform any user might be
using? Anyway, aren't such controls part of the "browser chrome"
which is outside the page "canvas" which any coding in your site can
work with?
 
B

Bergamot

jimmy said:
2. What i've done is that i check the coordinates of the browser for
an event in the body unload method.
If the coordinates match to those of the close button, it confirms
the window closing event by closing the browser.

Hmmm... so how do you check the coordinates of closing the window via
Alt+F4 or some other method?
So real problem arises when i resize the window

I think the problem is more that you are attempting to detect something
that cannot be reliably detected.
i want to capture the window.close() event and then proceed
accordingly.

I'm curious why you think you need to do this at all.
 
J

jimmy

@Dan:-
"HTML can't capture and react to any events; it's a markup language,
not a programming language. "
Exactly, i'm trying to capture the event in the javascript...i thought
that was implicit...
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.

And i'm not getting the exact coordinates...all i'm getting is the
range i.e.
****************************************************
if (event.clientY < 0 && event.clientX > 500)
{
//don't ask the user to save the data
}
***************************************************
Here event.clientY < 0 ensures that the button wasn't clicked in the
body and event.clientX >500 ensures that the function is not called
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 the problem i m facing

@Berg "Hmmm... so how do you check the coordinates of closing the
window via
Alt+F4 or some other method? "
That is exacly my problem...how does one capture the window closing
event...

"I'm curious why you think you need to do this at all. "
I suppose the description above would serve the purpose !
 
J

J.O. Aho

jimmy said:
Hi all,
I want to capture the event when the browser's close button is clicked
in a jsp.

jsp is serverside and won't be aware of what happens on clientside if you
don't return values using POSt or GET methods (cookies can slao used, but
would just be more work).


http://en.wikipedia.org/wiki/JavaServer_Pages


I guess you are talking about javascript, which isn't java and therefore can't
be jsp.
 
J

jimmy

yeah u r right ...
i'm talking about the code written in the javascript of an html
page...
is there any way i can capture the window closing event in the
javascript?
 
B

Bergamot

Please, if you are going to use the dreadful google groups to post to
Usenet, learn how to quote properly. AIUI, google has changed the UI
(again), but this article might point you in the right direction:
http://www.safalra.com/special/googlegroupsreply/

Even better, get a real newsreader and don't use google groups for
posting at all. Dang, even Outlook Express is better than GG.
@Berg "Hmmm... so how do you check the coordinates of closing the
window via Alt+F4 or some other method? "
That is exacly my problem...how does one capture the window closing
event...

window.onunload or
<body onunload="...">

are all you have, AFAIK. BTW, you might have better luck posting your
query in a JavaScript newsgroup. comp.lang.javascript is over there ->
 
J

J.O. Aho

jimmy said:
yeah u r right ...
i'm talking about the code written in the javascript of an html
page...
is there any way i can capture the window closing event in the
javascript?

I really doubt there is any way, closes would be "unload", it's closest of the
events listed on this event list page:
http://www.w3schools.com/jsref/jsref_events.asp

When you close down a window, you don't want some javascript to keep it open
for a long while, you want it to close down at once, and I guess thats why
there aren't any close button event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,477
Members
44,898
Latest member
BlairH7607

Latest Threads

Top