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

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!!!

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.

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