Prevent user from reloading page using jquery or javascript

Possible duplicate:
Prevent updating any form of page using jQuery / Javascript

how can I prevent a user from reloading (refreshing) an html page using javascript or jquery.

after loading the page for the first time, I want the user to not reload the page, either by pressing F5, or updating from the browser or by any means.

Can i do that?

Note: I am trying window.onbeforeunload, but I did not know how to stop the window.onload event from it.

Any help?

+5
source share
2 answers

No, you can’t. If the user wants to reload the page, you cannot stop them.

+6

, , . , , :

:

<script>
window.onbeforeunload = function (e) {
e = e || window.event;

// For IE and Firefox prior to version 4
if (e) {
    e.returnValue = 'Sure?';
}

// For Safari
return 'Sure?';
};
</script>

: http://jsfiddle.net/gopi1410/NujmL/

Default F5, :

document.onkeydown = function(event) {
  if(window.event){
        event.preventDefault();
  }
}
+7

All Articles