Important alert: (current site time 7/15/2013 1:50:24 PM EDT)
 

VB icon

No Refresh, No NAV Back*, No Right Click, No Backspace, etc.

Email
Submitted on: 6/19/2001 4:37:55 PM
By: Matt Khoury  
Level: Advanced
User Rating: By 10 Users
Compatibility: JavaScript
Views: 46728
author picture
(About the author)
 
     To disable the right click, the backspace (for navigation purposes), and the refresh.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: No Refresh, No NAV Back*, No Right Click, No Backspace, etc.
' Description:To disable the right click, the backspace (for navigation purposes), and the refresh.
' By: Matt Khoury
'
' Assumes:*Obviously for this script to run effectively you MUST open up a NEW browser window in IE using JScript. Please note that for this script to run effectively it is recommended that you open a new browser using script to disable the navigation, link bars, etc., etc. Also, the cool thing about this code is that the JavaScript disables itself once the cursor is in a text are box, or input box - VERY COOL! PLEASE NOTE, THIS CODE WAS ONLY TESTED IN IE 5.0+. If you feel you can add to this code to make it better, be my guest. Send me the updated code and I will paste it right here.
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=2250&lngWId=14'for details.'**************************************

<HTML>
<HEAD>
	<TITLE>NO REFRESH, NO REFRESH, NO BACKSPACE, NO ALT-BACKSPACE, ETC., ETC..</TITLE>
<SCRIPT LANGUAGE=JAVASCRIPT>
var oLastBtn=0;
	bIsMenu = false;
	//No RIGHT CLICK************************
	// ****************************
	if (window.Event) 
	document.captureEvents(Event.MOUSEUP); 
	function nocontextmenu()
	{ 
	event.cancelBubble = true 
	event.returnValue = false; 
	return false; 
	} 
	function norightclick(e) 
	{ 
	if (window.Event) 
	{ 
	if (e.which !=1) 
	return false; 
	} 
	else 
	if (event.button !=1) 
	{ 
	event.cancelBubble = true 
	event.returnValue = false; 
	return false; 
	} 
	} 
	document.oncontextmenu = nocontextmenu; 
	document.onmousedown = norightclick; 
	//**************************************
	// ****************************
	// Block backspace onKeyDown************
	// ***************************
	 function onKeyDown() {
	 	if ( (event.altKey) || ((event.keyCode == 8) && 
	 			(event.srcElement.type != "text" &&
	 			event.srcElement.type != "textarea" &&
	 			event.srcElement.type != "password")) || 
	 			((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82)) ) ||
	
	
	 			(event.keyCode == 116) ) {
	 		event.keyCode = 0;
	 		event.returnValue = false;
	 	}
	 }
</SCRIPT>
</HEAD>
<BODY onKeyDown="onKeyDown();" BGCOLOR="#639ace" MARGINHEIGHT="0" MARGINWIDTH="0" TOPMARGIN="0" LEFTMARGIN="0">
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
	<TR>
		<TD><H3>NO REFRESH, NO REFRESH, NO BACKSPACE, NO ALT-BACKSPACE, ETC., ETC..</H3></TD>
	</TR>
	<TR>
		<TD>Please note that for this script to run effectively it is recommended that you open a new browser using script to disable the navigation, link bars, etc., etc..</TD>
	</TR>
</TABLE>
</BODY>
</HTML>


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

6/20/2001 10:19:37 AMsmsforce

Great code. Thanks for sharing!
(If this comment was disrespectful, please report it.)

 
6/22/2001 9:19:08 PMbaroberts

Thanks. This code is the bomb!
(If this comment was disrespectful, please report it.)

 
3/19/2002 4:02:45 PMLeo

Cool thanks a mil!
(If this comment was disrespectful, please report it.)

 
3/25/2002 10:44:07 AMJonn

Is this supposed to work in Netscape? Cause it doesn't.
(If this comment was disrespectful, please report it.)

 
3/25/2002 12:03:20 PMMatt

John, did you read the description? This only works in IE. No Netscape.
(If this comment was disrespectful, please report it.)

 
4/12/2002 7:37:07 AMLloyd Bottomley

This rocks! It works perfectly from the word go. No hassles! Your small script is nice and clean as well.
(If this comment was disrespectful, please report it.)

 
6/24/2002 4:52:04 AMRichard

Thanks, A good piece of code but...it doesn't work to lock the alt-left and alt-right keys (same behavior as back and next buttons).Is there a way to lock the alt key with javascript ?
(If this comment was disrespectful, please report it.)

 
2/4/2003 10:16:39 AM

Very nice, but you forgot an event:

F11: in IE, this is 'to fullscreen mode', which will give you a toolbar, address bar, and links bar.

I suspect you need something like || (event.keyCode == 122)
(If this comment was disrespectful, please report it.)

 
11/7/2003 4:40:38 AM

Add event.keyCode == 117 this also .It will disable F6 ,otherwise F5 won't work, After pressing F6 , F5 refreshes the page.
(If this comment was disrespectful, please report it.)

 
3/8/2004 2:56:46 PMjamie phillips

Man this Rock! I have been Looking all over the place for a good disable rick click without a Msgbox pop for a Instant Messanger system I am designing You saved me!!!!!!!!
(If this comment was disrespectful, please report it.)

 
7/14/2004 4:48:35 PM

email me at keith@trifi.com if you want it, basically you just need to replace event with a var reading for netscape
example:
function nocontextmenu(evt)
{
var evNorE=(evt)?evt:event;


(If this comment was disrespectful, please report it.)

 
8/19/2004 5:58:03 PM

//This is my modified version
//including alt-left alt-right arrows
//My changes on onKeyDown function:

function onKeyDown() {

if (((event.keyCode == 8) &&
(event.srcElement.type != "text" &&
event.srcElement.type != "textarea" &&
event.srcElement.type != "password")) ||
((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82))) ||
//Added: keyCodes for left and right
//arrows ((event.altKey) && ((event.keyCode == 37) || (event.keyCode == 39))) ||

(event.keyCode == 116)) {
//Modified alert('Not allowed!');
event.keyCode = 0;
event.returnValue = false;
}

}
//For some reason, i can't make it work
//without the alert.
//This is a small and obvious change
//Hope to be useful to somebody.
//Greetings from Colombia
(If this comment was disrespectful, please report it.)

 
3/13/2005 6:40:34 PM

Using IE 6 If you try a right click first then hit the backspace key afterwards the backspace is not disabled. You do need to try the right click first even though it is disabled.
(If this comment was disrespectful, please report it.)

 
3/13/2005 8:06:56 PM

Further to my above note it only happens on pages with no text, textarea or password fields.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.