views:

614

answers:

4

Hi All,

I want to disable browser refresh using javascript. Actually i am using window.onbeforeonload abd i don't want it will be called when user refresh the browser. what is the best way to do it?

Regards,

Salil Gaikwad

+1  A: 

Here you can find how to do it.

Enrique
sorry it's not working 4 me.it's still refreshing the browser.
Salil
As far as I know, you can not do it at least in IE, you could probably override the F5 keypress for firefox and chrome. So it is not feasible to implement something like this. You better find some other way to get round of disabling F5.
schrodinger's code
+1  A: 

From the site Enrique posted:

window.history.forward(1);
document.attachEvent("onkeydown", my_onkeydown_handler);
function my_onkeydown_handler() {
    switch (event.keyCode) {
        case 116 : // 'F5'
            event.returnValue = false;
            event.keyCode = 0;
            window.status = "We have disabled F5";
            break;
    }
}
kzh
A: 

You have a design flaw with your page, consider adding a "Refresh..." button to the page instead, or have it dynamically updating like stackoverflow.com does.

Steve-o
A: 

From the site Enrique posted:

only works for IE.

try this link http://www.openjs.com/scripts/events/keyboard_shortcuts/

rbawaskar