admin管理员组文章数量:1356824
I would like to use some kind of preventDefault
function to overwrite what hitting the refresh button on the browser does (or also pressing CTRL/CMD+R
).
Is there something that allows me to prevent refreshing the page?
I tried this but it doesn't seem to do anything in Firefox.
window.onunload = function(){
alert("unload event detected!");
}
I would like to use some kind of preventDefault
function to overwrite what hitting the refresh button on the browser does (or also pressing CTRL/CMD+R
).
Is there something that allows me to prevent refreshing the page?
I tried this but it doesn't seem to do anything in Firefox.
window.onunload = function(){
alert("unload event detected!");
}
Share
Improve this question
edited Jan 14, 2021 at 11:10
Erik Kaplun
38.3k15 gold badges102 silver badges113 bronze badges
asked May 29, 2013 at 5:36
Todd JenkTodd Jenk
3111 gold badge3 silver badges13 bronze badges
2
-
1
maybe
window.onunload = window.onbeforeunload = function(){
– Ohgodwhy Commented May 29, 2013 at 5:38 - this kind of works ... thanks – Todd Jenk Commented May 29, 2013 at 7:33
1 Answer
Reset to default 8You can use onbeforeunload
to prompt whether they'd like to leave:
window.onbeforeunload = function() {
return "Are you really sure?\nI don't know why anyone would want to leave my beautiful website!";
};
However, you can't override it any more than that.
本文标签: javascriptIs there a way to overwrite the refresh button actionStack Overflow
版权声明:本文标题:javascript - Is there a way to overwrite the refresh button action? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744071503a2585972.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论