Disable Right Click Context Menu On Images
Disabling right click or context menu is one of the more popular ways to prevent images from being stolen from a blog.
The better way would be to disable right click only on images. After all it’s the images they’re trying to protect, so this method is more appropriate to the task and more importantly it’s far less annoying to readers . It is impossible to keep people from stealing images posted on your blog or website.
A. Disable right click on all images
Go to your template Edit HTML and paste the following script right after the
</head>
tag.Copy the code below
<script type="text/javascript">
//<![CDATA[
function nocontext(e) {
var clickedTag = (e==null) ? event.srcElement.tagName : e.target.tagName;
if (clickedTag == "IMG") {
alert(alertMsg);
return false;
}
}
var alertMsg = "Image context menu is disabled";
document.oncontextmenu = nocontext;
//]]>
</script>
The script will disable the context menu and replace it with this alert box:
- You can replace the message with whatever you like in line 15, or
- If you don’t want the alert box to appear at all, just delete the line or comment it out, like this:
//var alertMsg = "Image context menu is disabled";
Click on any image in this post to see it in action.
B. Disable right click on a single image
To disable context menu on a single image you need to add this piece of code (a context menu event handler) in the img tag:
oncontextmenu='alert("Image context menu is disabled");return false;'
Open the post in post editor, switch to HTML mode, locate the img tag of the image you want to disable and then insert the code inside the tag.
For Example:
This is an original image tag:
<img border="0" src="YOUR IMAGE URL.JPG" />
Once you added the context menu event handler, it should look like this:
<img border="0" oncontextmenu="alert("Image context menu is disabled");return false;" src="YOUR IMAGE URL.JPG" />