By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,842 Members | 2,440 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,842 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Be*****@gmail.com 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.

Aug 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.