How to distinguish between page-refresh and window-close ?

Discussion in 'Javascript' started by BennyVK@gmail.com, Aug 28, 2006.

  1. Guest

    Hi,

    I'm not sure if this question should go to the "JavaScript" section;
    but I'm open to non-JavaScript (like VBScript) options too. So, I'm
    posting this here.

    I have the following problem:

    For my application, I need to ask a confirmation when the user closes
    the browser-window. If the answer is positive, I would like to log-off
    the session and close the window. If the answer is negative, I would
    like to stay back (no logging-off, no closing the window).

    I can't do this in the window.unload event because the window is
    already closed when the unload event is fired. I tried doing this in
    the beforeUnload event. But the beforeUnload event gets called even
    when I refresh the page and in that case, I don't want to ask this
    question or logoff.

    Can somebody help me in the above scenario? Please...

    Thanks,
    Benny Varghese
     
    , Aug 28, 2006
    #1
    1. Advertising

  2. Dag Sunde Guest

    wrote:
    > Hi,
    >
    > I'm not sure if this question should go to the "JavaScript" section;
    > but I'm open to non-JavaScript (like VBScript) options too. So, I'm
    > posting this here.
    >
    > I have the following problem:
    >
    > For my application, I need to ask a confirmation when the user closes
    > the browser-window. If the answer is positive, I would like to log-off
    > the session and close the window. If the answer is negative, I would
    > like to stay back (no logging-off, no closing the window).
    >
    > I can't do this in the window.unload event because the window is
    > already closed when the unload event is fired. I tried doing this in
    > the beforeUnload event. But the beforeUnload event gets called even
    > when I refresh the page and in that case, I don't want to ask this
    > question or logoff.
    >
    > Can somebody help me in the above scenario? Please...
    >


    Yes, I can help you...

    I had exactly the same question here some months ago, and with the
    help of a lot of the regulars in this group we came to a conclusion:

    Forget it! It can't be done in any reliable way!
    I'm sorry.

    Your best bet is a session timeout on the serverside.

    --
    Dag.
     
    Dag Sunde, Aug 28, 2006
    #2
    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. mosfet
    Replies:
    6
    Views:
    1,373
    Rolf Magnus
    Nov 27, 2003
  2. Vinodh Kumar P
    Replies:
    1
    Views:
    357
    Jack Klein
    Dec 12, 2003
  3. J P Singh
    Replies:
    3
    Views:
    366
    Howard Rothenburg
    Feb 11, 2004
  4. Iñaki Baz Castillo
    Replies:
    7
    Views:
    937
    Iñaki Baz Castillo
    Jan 12, 2010
  5. Shang Wenbin

    close current window using window.close()

    Shang Wenbin, Sep 1, 2005, in forum: Javascript
    Replies:
    10
    Views:
    422
    Gérard Talbot
    Sep 2, 2005
Loading...

Share This Page