Browser's close button

Discussion in 'HTML' started by jimmy, Apr 2, 2007.

  1. jimmy

    jimmy Guest

    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??
    jimmy, Apr 2, 2007
    #1
    1. Advertising

  2. 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?

    --
    Jukka K. Korpela ("Yucca")
    http://www.cs.tut.fi/~jkorpela/
    Jukka K. Korpela, Apr 2, 2007
    #2
    1. Advertising

  3. jimmy

    jimmy Guest

    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.
    jimmy, Apr 2, 2007
    #3
  4. jimmy

    Dan Guest

    On Apr 2, 8:03 am, "jimmy" <> wrote:
    > 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?

    --
    Dan
    Dan, Apr 2, 2007
    #4
  5. jimmy

    Bergamot Guest

    jimmy wrote:
    >
    > 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.

    --
    Berg
    Bergamot, Apr 2, 2007
    #5
  6. jimmy

    jimmy Guest

    @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 !
    jimmy, Apr 3, 2007
    #6
  7. jimmy

    J.O. Aho Guest

    jimmy wrote:
    > 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.

    --

    //Aho
    J.O. Aho, Apr 3, 2007
    #7
  8. jimmy

    jimmy Guest

    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?
    jimmy, Apr 3, 2007
    #8
  9. jimmy

    Bergamot Guest

    jimmy wrote:
    >


    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 ->

    --
    Berg
    Bergamot, Apr 3, 2007
    #9
  10. jimmy

    J.O. Aho Guest

    jimmy wrote:
    > 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.


    --

    //Aho
    J.O. Aho, Apr 3, 2007
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: Controlling Close button of browser

    Kevin Spencer, Jun 26, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    509
    Kevin Spencer
    Jun 26, 2003
  2. Denon
    Replies:
    1
    Views:
    558
    Saravana [MVP]
    Nov 14, 2003
  3. Iñaki Baz Castillo
    Replies:
    7
    Views:
    815
    Iñaki Baz Castillo
    Jan 12, 2010
  4. Replies:
    0
    Views:
    471
  5. Replies:
    2
    Views:
    164
    Thomas 'PointedEars' Lahn
    Mar 5, 2008
Loading...

Share This Page