Hi friends

I have used this script for avoid right click in my webpage. I want to disable " savepage as" in file menu . please let me know ur suggestion.

<script language="JavaScript">
	document.onmousedown=click;
	function click() {
		if ((event.button==2)) {
		alert("Sorry you didnt access right click");
		}
	}
	</script>

Dani AI

Generated

Right-click blocking is only a cosmetic deterrent. asked about stopping "Save Page As" and @Cholesterol posted an IE-style right-click script — that kind of approach can stop a casual user from using the context menu in some browsers, but it does not stop the browser from receiving the page and saving it. Browsers must download HTML, CSS, JS and images to render a page, so any resource the browser has can be saved by other means (menu, Ctrl+S, developer tools, curl/wget, or screenshots).

For cross-browser event handling use standard listeners rather than old IE-only APIs. The contextmenu event can be prevented in modern browsers, and keyboard shortcuts can be intercepted, but these are partial measures only. See MDN for the contextmenu event and KeyboardEvent.key for implementation details: MDN: contextmenu event and MDN: KeyboardEvent.key.

If the goal is real protection, consider alternatives:

  • Keep valuable content behind authenticated endpoints and check authorization server-side.
  • Apply visible or user-specific watermarks to images/PDFs generated server-side so leaks can be traced.
  • Deliver video via encrypted streaming/DRM rather than static files.
  • Provide excerpts or low-resolution previews on the public site and full assets only after verification.

Final note: disabling right-click harms usability and accessibility and gives a false sense of security. Use client-side blocking only as a minor deterrent and rely on server-side controls or DRM when true protection is required.

As i remember I saw the answer for this question reading . You can try this code:

<html> 
<head> 
<META http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
<TITLE>JavaScriptBank.com -> JavaScript -> Security -> No Right Click</title></head> 
<body bgcolor="#000000" text="#FFFF00" link="#00FF00" vlink="#00FF00" alink="#00FF00"> 
<SCRIPT language=JAVASCRIPT> 
var oLastBtn=0; 
bIsMenu = false; 
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.onmousedown = norightclick; 
document.oncontextmenu = nocontextmenu;  
</SCRIPT> 

</body></html>

hi chesterol

thanks for ur reply. ur code has been working in IE but not functional in Firefox. how to solve this browser compatibility issue

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.