Page 1 of 1

refresh the page

Posted: Thu Oct 13, 2005 4:29 pm
by rajan
how to restrict the user from refreshing the page

Posted: Thu Oct 13, 2005 4:38 pm
by Burrito
in a regular browser window it can't be done.

in a pop-up, you could prevent a right click, but that doesn't work on all browsers, even still the 'ole F5 would probably kill that idea anyway.

Posted: Fri Oct 14, 2005 6:28 am
by foobar
You can block the F5 key with the following code:

[Note - you have to call this function like so: <tag onkeydown="kill_page_refresh();">]

Code: Select all

/**
 * Disables page refreshing.
 */
function kill_page_refresh(e) {

  if (window.event) {
    if (event.keyCode==116||(event.keyCode==82&&event.ctrlKey)) {
	  event.returnValue = false;
	  event.keyCode = 20;
	}
  }
  return true;
}
Only tested on IE though.

Posted: Fri Oct 14, 2005 6:37 am
by Roja
foobar wrote:You can block the F5 key with the following code
That leaves shift-f5, clicking the refresh button in the browser, right-clicking, and of course any plugins the user might have.
rajan wrote:how to restrict the user from refreshing the page
You can't, and you shouldn't. Doing so removes functionality from users that they may need.

Posted: Fri Oct 14, 2005 7:03 am
by n00b Saibot
I thought a simple window.unload will do this job but i noticed the side-effect will be user not able to navigate to other page or close the window :!: had not IE implemented a confirm box to ask the user - "Are you sure you want to navigate away from this page". Brrrrr.... I would have locked myself in :lol: