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

B

BennyVK

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
 
D

Dag Sunde

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.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top