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.
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.
You just can't.
The only solution is to use window.onbeforeunload to catch when user leaves page - reloads or uses back.
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.