Computer Hope

Other Pages

Home
Site map
Computer help

Dictionary
News
Q&A
What's new

Tools

E-mail this page
Print Preview
Edit this page




 

Disable mouse right-click

Information

Before 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 in document CH000977.

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. In addition to this issue 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. In order for this to work JavaScript must be enabled on the browser.
  • View the source code and locate the image or text they wish 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.

Example

Because each of the below examples of source code given 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 will only display a copyright notice when the user is clicking on the actual image you wish 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) {
alert(theMsg);
}
//-->
</script>

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

<IMG SRC="http://www.computerhope.com/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.

<script>
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;

</script>

Source code solution 3:

In addition to the above example users 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 below example.

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

 

 

 

Index

Category:
Cool Tricks

Companies:
None

Related Pages:
HTML Help

 

Resolved

Were you able to locate the answer to your questions?

Home - Computer help - Contact - Dictionary - Links
Link to Computer Hope - Bookmark Computer Hope