Javascript: how to overwrite page reload event?

≡放荡痞女 提交于 2019-12-08 09:41:37

问题


What I mean is - when user clicks on some browser page reload/refresh button we do not want to reload page - we want to capture that event and call some function (for simple example one with some alert). I need it to work in IE6 and up and Chrome and Firefox3+ of course. How to do such thing (not using jQuery and other libs)?


回答1:


You cannot. You can't change the operating system functionality from within any browser except IE.




回答2:


It's not possible.

You can detect when an unload occurs, but you can't detect what caused the unload and you can't cancel it without the user's consent. For instance, typing a new address in the address box, clicking a link, submitting a form, selecting a bookmark or refreshing the page will all fire an onbeforeunload event.



来源:https://stackoverflow.com/questions/4376483/javascript-how-to-overwrite-page-reload-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!