refresh the page

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
rajan
Forum Contributor
Posts: 110
Joined: Sun Aug 28, 2005 7:42 pm
Location: Lucknow, UP, India

refresh the page

Post by rajan »

how to restrict the user from refreshing the page
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post 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.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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:
Post Reply