有没有办法覆盖刷新按钮操作?

Tod*_*enk 3 javascript jquery html5

我想使用某种preventDefault函数覆盖浏览器上的刷新按钮(或者按CTRL/CMD + R).

有什么东西可以让我阻止刷新页面吗?

我试过这个,但它似乎没有在Firefox中做任何事情.

window.onunload = function(){
     alert("unload event detected!");
}
Run Code Online (Sandbox Code Playgroud)

ick*_*fay 5

您可以onbeforeunload用来提示他们是否愿意离开:

window.onbeforeunload = function() {
    return "Are you really sure?\nI don't know why anyone would want to leave my beautiful website!";
};
Run Code Online (Sandbox Code Playgroud)

但是,您不能再覆盖它.