unload for close not refresh

Discussion in 'Javascript' started by DonO, Mar 2, 2004.

  1. DonO

    DonO Guest

    I have a jsp page that updates information as a user enters form
    fields. It's part of an AP system where a user can select a category,
    and then it refreshes the page, pulling relative info into other form
    fields.

    The issue we have is that closing the window with the [x] closer does
    not clear out buffered info. We have a "close" button that will do
    this. I tried doing an "onunload" to call the same function as the
    close button, but since the form is reloaded as the user tabs through
    fields, it calls the onunload and the window closes.

    Does anyone have an idea of how to call the close function when the
    window closes, but not when it reloads?

    Thanks for any help.

    D.
     
    DonO, Mar 2, 2004
    #1
    1. Advertising

  2. On 2 Mar 2004 14:45:23 -0800, DonO <> wrote:

    > I have a jsp page that updates information as a user enters form
    > fields. It's part of an AP system where a user can select a category,
    > and then it refreshes the page, pulling relative info into other form
    > fields.
    >
    > The issue we have is that closing the window with the [x] closer does
    > not clear out buffered info. We have a "close" button that will do
    > this. I tried doing an "onunload" to call the same function as the
    > close button, but since the form is reloaded as the user tabs through
    > fields, it calls the onunload and the window closes.
    >
    > Does anyone have an idea of how to call the close function when the
    > window closes, but not when it reloads?


    That cannot be done reliably. onunload is called at different times by
    different browsers and some, like Opera, do not fire onunload when the
    browser is closed.

    Even if it were, it is highly unlikely that anything you do will actually
    have an affect as a browser probably won't open a connection to a server
    when the user is trying to close it.

    Instead, impress upon your users the importance of sending their data
    before closing their browser.

    Mike

    --
    Michael Winter
    d (replace ".invalid" with ".uk" to reply)
     
    Michael Winter, Mar 2, 2004
    #2
    1. Advertising

  3. DonO

    DonO Guest

    Michael Winter <> wrote in message news:<>...
    > That cannot be done reliably. onunload is called at different times by
    > different browsers and some, like Opera, do not fire onunload when the
    > browser is closed.
    >
    > Even if it were, it is highly unlikely that anything you do will actually
    > have an affect as a browser probably won't open a connection to a server
    > when the user is trying to close it.
    >
    > Instead, impress upon your users the importance of sending their data
    > before closing their browser.
    >
    > Mike


    Thanks for the reply Mike. Fortunately (I suppose) this is for an
    internal project, so I know all my users will be using IE 5.5 or
    higher.

    I did find something that works, but is really ugly...

    I added a new form at the bottom of the page named close_check with a
    hidden field with the name "close_me" and default value "1" (true).

    I put in a call to a function called "tabCheck()" in all the places
    where the tabbing forces the page to reload. This function would set
    the "close_me" value to "0" (false) like this:
    document.form_check.close_me.value = 1;

    My onunload then called a function to which checked the value of
    "close_me" if it was "1" it did the close, otherwise, it set the value
    back to "1".

    So the order of how things happen is:

    1) User tabs over fields that reload page
    2) "close_me" is set to false
    3) onunload function is kicked off
    4) Because the close_me value is false, it does NOT close the window

    Other scenario:

    1) User clicks the [x] to close the window
    2) onunload function is kicked off
    3) Because the value is set to 1 by default, or at the end of checking
    it above, it is true, and the close function is called, just as if
    they clicked the "Close" button we have on the page.

    So far it seems to work. If anyone has any better ideas, I'm open to
    suggestion. For now, with IE this option is ok.

    Thanks again,
    D.
     
    DonO, Mar 3, 2004
    #3
    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. S_K
    Replies:
    6
    Views:
    712
    Russell
    Dec 7, 2007
  2. Dani
    Replies:
    3
    Views:
    505
  3. Iñaki Baz Castillo
    Replies:
    7
    Views:
    937
    Iñaki Baz Castillo
    Jan 12, 2010
  4. Al Fraser

    Browser Close / New URL / Form UnLoad()

    Al Fraser, Sep 30, 2003, in forum: Javascript
    Replies:
    1
    Views:
    208
    David Dorward
    Sep 30, 2003
  5. Donkey Cart Racer

    call a function on page close NOT unload

    Donkey Cart Racer, Jul 5, 2006, in forum: Javascript
    Replies:
    1
    Views:
    122
    Laurent Bugnion
    Jul 5, 2006
Loading...

Share This Page