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.
While it is effective to some extent in deterring casual image theft, it also frustrates honest readers by denying them access to many useful functions associated the right click such as going Back, page Reload, Bookmark and Open Link In New Window.
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, but hey this is better than doing nothing right?).
a) Disable right click on all images
Go to your template Edit HTML and paste the following script right after the </head> tag.
<script type="text/javascript">
//<![CDATA[
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Disable context menu on images by GreenLava (BloggerSentral.com)
Version 1.0
You are free to copy and share this code but please do not remove this credit notice.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
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 prefer not to show the alert box, just delete or comment out code line 11 and 15. To comment out a line of Javascript, place two slashes "//" in front of the line, 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.
An example:
This is the original image tag:
<img border="0" src="http://3.bp.blogspot.com/-MK7fhu_0MKA/SlWREIy96AI/AAAAAAAAAPo/d-w9hOxZkqU/s1600/2008_10260151.JPG" />
Once you added the context menu event handler, it should look like this:
<img oncontextmenu='alert("Image context menu is disabled");return false;' border="0" src="http://3.bp.blogspot.com/-MK7fhu_0MKA/SlWREIy96AI/AAAAAAAAAPo/d-w9hOxZkqU/s1600/2008_10260151.JPG" />
Enjoy!
38 comments to "Disable right click context menu on images"
nice tips, thank so much
Will that prevent folks from putting your pics on Pinterest?
Thanks for this useful post, i will use this script so that noone will copy my article and posted in other blogs. the script I've used is "warning: copyright protected". I guess this will protect our work online especially if the articles are our own ideas, own intellectual property.
Thanks for this post, I've been looking for this for a long time. Keep it up bro. you have so many useful blogger tips and tricks in this blog. You deserved to have a Blogger Sentral domain name.
Thank for share this code.
How to use this code with "back to top" by right click
I have been looking for a hack like this just for images - thankyou so so much Greenlava........perfect timing!
love the tips.. thanks for sharing
I was actually wondering why on some blogs my right mouse button is disabled. Now I know! Thanks for sharing!
thanks Greenlava, now i can save my self-drawing images.
@Gina
No it won't prevent (Pinterest) pinning.
oke. its works.
Well, people can simply do a PrintScreen or a Cut PrintScreen... Sometimes even more faster than saving the actual image. If people want to copy, they'll copy. Also, the web is not as regulated as print media, although this might change in the upcoming years. Intellectual property is a big business. Here in China, more and more efforts are done towards intellectual property rights. But it takes time to change the mentality of people.
But even if you disable the right click you pic may be "borrowed" from the google pic search.
Very nice info.
Anyway, if people really want to steal, they'll do it.
Still back to the root, the mentality of people.
Good Script
nice trick. through this my images can be protected. but what to do for the users who use image plugin in chrome for croping images from websites?
Tried the pix trick, friends hated it ... What's the point of blogging if you're not sharing... If you give something, later you'll get something in return. The perfect balance in life and even in the blogger world. Anyway great info.. Much more detailed form the script i used. Would do great on my clients blog... if they request for it.
nice article,
Good tips. But I guess people can still print screen. :)
By the way, I have just submitted a guest post to you. Hopefully it's suitable for your blog.
Good to know. Obviously people will take something if they really want to, but why make it any easier for them?
Hey There is mistake??? in where we have to place the code..
Go to template-->Edit HTML and paste the following script not right after the /head tag...but place it before /head tag..
okk ..
Thanks for giving nice good code can u give me code for how to disable the copy of text from blog...
-----urs SAI KRISH
when i delete the line or comment the line, the script will not work..weird
@Sai Krish
There is no mistake. You can do it either way, before or after.
Thanks for this it is really helpfull
@Greenlava
Hoo Its works before and after the /head tag
Thank U
--urs NaSaSrKr(alias Sai Krish)
thanks for sharing information.
Thanks so much for your help.
Thanks!! This is exactly what I was looking for :D
what a great trick! works perfect
thank u
thanks BS. This trick is really awesome. :-O
That's a useful one, I did something like this some time before on my blogger blog but the attribute was absolute and disabled right click images, select text and many other things. I had no choice but to remove it as soon as i can. But this trick seem better as it wont be that frustrating for honest users like you said.
thank you so muck i like it thank for sharing it
Nice tips.....work like a magic on my blog....tq man:)
Thank you so much :)
Nice trick bro but it is easily breakable through firefox without using any code,extensions,plug-ins or even software.
I like the script, but it if the browser restricts running scripts, for example by having the NoScript add-on, the script fail to prevent image copying.
Thanks for this.
I have a question though:
The code works as is but if I delete or comment out line 15, the right click menu still shows.
What am I doing wrong?
@Maia
You need to delete line 11 as well.
Thanks. it works. i use this because someone is copy my pictures to his blog.
To ensure proper display, HTML/XML/Javascript need to be escaped first using this escape tool. Then paste the escaped code here. For personalized help, you can HIRE ME.