views:

33

answers:

2

How can i write JS function to catching a Reload Button (on browser) then i pressed on. I want to pop up alert something like that.

etc. -> and back button too.

Thank you.

+1  A: 

You just can't.

The only solution is to use window.onbeforeunload to catch when user leaves page - reloads or uses back.

Māris Kiseļovs
A: 

You can't detect these directly, you can use onbeforeunload to handle any unloading, including closing the browser, for example:

window.onbeforeunload = function() { return "Are you sure?"; };

But you can't detect what caused it, e.g. closing would as well, so would going forward in history.

Nick Craver