Disable mouse right-click

Updated: 12/20/2017 by Computer Hope


disable computer mouse right-clickBefore adding any of the below source code to your web page to disable the right-click we highly suggest that 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 most browsers and browsers such as Opera do not allow the right-mouse button to be disabled. Also, disabling the right-click can cause serious accessibility issues and often only angers users.

Finally, there are so many ways for users to get around this method of protection that it shouldn't even really be considered a method of protecting your data. Below are some examples of how a user may get around this to steal your content.

  • 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 other open program.
  • If wanting to copy text a user can highlight the text and click Edit and then Copy to copy the text and paste it elsewhere.


Because each of the examples below do not work in every browser and making this page as a demo page would prevent some users from copying the below code no examples are given.

Source code

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 is clicking on the actual 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 has been 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 3

You can also add the below commands into your HTML <body> tag. Which will disable 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">