Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to overwrite the refresh button action?

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!");
}
like image 902
Todd Jenk Avatar asked May 29 '13 05:05

Todd Jenk


1 Answers

You 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.

like image 162
icktoofay Avatar answered Oct 12 '22 01:10

icktoofay