unload for close not refresh

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DonO

    unload for close not refresh

    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.
  • Michael Winter

    #2
    Re: unload for close not refresh

    On 2 Mar 2004 14:45:23 -0800, DonO <don@orbandesig n.com> wrote:
    [color=blue]
    > 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?[/color]

    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
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • DonO

      #3
      Re: unload for close not refresh

      Michael Winter <M.Winter@bluey onder.co.invali d> wrote in message news:<opr39d37m v5vklcq@news-text.blueyonder .co.uk>...[color=blue]
      > 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[/color]

      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_c heck.close_me.v alue = 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.

      Comment

      Working...