...

View Full Version : How to detect browser Refresh or Close?



Mahendra.Ph
07-16-2010, 12:23 PM
In my application I want user to take an "Exit Survey"(Independent website) when he is leaving the application. As name explains, It should happen only when user closes current browser tab or browser window. Its possible using JavaScript OnUnload event. But the problem is that this event occurs on

1. close of browser tab
2. close of browser window
3. click of any internal page link(i.e anchors and form buttons)
4. click of browser's Refresh button
5. click of browser's Back/Forward button

I have handled first 3 cases but not able to detect Refresh and Back/Forward button click.
Has anybody of you implemented such functionality??

Thanks in advance!!!

DevonHartigan
07-28-2010, 06:31 PM
Trust me on this one. It is simply not possible. I have recently tried to do pretty much the exact same thing, and researched this topic.

It cannot be done. Period. I ended up with your 3 first points too.

There is no way to detect if a user press the refresh or back navigation button.

DevonHartigan
07-28-2010, 06:37 PM
You can also see:

http://stackoverflow.com/questions/291553/is-there-a-way-in-javascript-to-detect-if-the-unload-event-is-caused-via-a-refres

and

http://stackoverflow.com/questions/181189/to-detect-if-the-user-is-closing-the-ie-browser-apart-from-onunload-event-as-it



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum