开发者

How to JS function to catching Reload Button

开发者 https://www.devze.com 2023-01-19 04:42 出处:网络
How can i write JS function to catching a Reload Button (on bro开发者_如何学Pythonwser) then i pressed on.

How can i write JS function to catching a Reload Button (on bro开发者_如何学Pythonwser) 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消