开发者

How to JS function to catching Reload Button

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜