Disable mouse right-click

Updated: 08/16/2021 by Computer Hope


Disable computer mouse right-click

Before adding any of the below source code to your web page to disable the right-click, we suggest you consider an alternative solution to protecting your data. If you're attempting to protect your images from being used without your consent, we suggest seeing alternative solutions to protecting your images online.

Today, many of the code examples used to disable the right-click no longer work in modern browsers. Also, disabling the right-click can cause serious accessibility issues and often only angers users. Also, there are so many ways for users to get around these methods of protection, as mentioned below.

  • Disable JavaScript. For this to work, JavaScript must be enabled on the browser.
  • View the source code and locate the image or text they want to copy in the source code.
  • Drag the image from the browser and drop it into the desktop, file manager, or another open program.


Source code solution one

If you do decide to try this we suggest using this solution, which only displays a Copyright notice when the user clicks the image you want to help protect. To use this code add the below section in-between the HTML <head> </head> tags.

<script language="JavaScript" Type="text/javascript">
function popupMsg(theMsg) {

After the above code is added into the header, when adding an image use code similar to the example below.

<IMG SRC="issues/pictures/cexample.gif" onMouseDown="popupMsg('This image is Copyrighted -- Computer Hope 2007')">

Source code solution two

Add the below code in-between the HTML <head> </head> tags.

var isNS = (navigator.appName == "Netscape") ? 1 : 0;
if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
return false;
function mousehandler(e){
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;

Source code solution three

You can also add the following commands into your HTML <body> tag. Which disables the keyboard and mouse in Internet Explorer.

oncontextmenu="return false" onselectstart="return false" ondragstart="return false"

Adding the above three commands to your body tag would make it appear similar to the example below.

<BODY oncontextmenu="return false" onselectstart="return false" ondragstart="return false">