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="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBWDMES55azVozm11If7zHJwAA0CTX3WCSDNB-HfW225RXzbifjRd3QLugO8pfVpgA5NzjKoqw_jmXF50EEUT2vSD9ncIuYJ4lIPSsfnuigwJrKCn1yDRygbZNr4Ru_EnviXHU9sJyp-D8/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="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBWDMES55azVozm11If7zHJwAA0CTX3WCSDNB-HfW225RXzbifjRd3QLugO8pfVpgA5NzjKoqw_jmXF50EEUT2vSD9ncIuYJ4lIPSsfnuigwJrKCn1yDRygbZNr4Ru_EnviXHU9sJyp-D8/s1600/2008_10260151.JPG" />
Enjoy!
55 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 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
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.
this is EXACTLY what I needed. Previously my page had right click disabled on images and text and that just wasn't working out. Now it is how I like it! I have a resource page (geared toward photographers, but everyone is welcome) and I listed this article as a reference!
Thanks for being so helpful.
Alisha Smith Watkins
http://amswphotography.blogspot.com/p/downloads-and-resources.html
Very nice coding, and how can i change the message title ?
@jabbar
You can't. It's a browser feature.
I am looking for this to control the copy of Images. Thanks a lot. --Jay
Greenlava
I have used the code for disabling a picture and it works good for a single image on a WP page, but when I select the picture it is shown on a new browser page and is the original size and the "disable right click image does not work.
Great tips, Greenlava, thank you! I am photographer and for me that is very essentially. But I found out, that if I outline not the post body only, but hole page (wider than the post body at least) - it has been copied both text and images without problems. Is there any possibility to prevent this issue? Thanks.
Great script.
For Wordpress sites I would recommend the WPCCP plugin. This works amazingly well ! http://wordpress.org/plugins/wp-content-copy-protection/
Thank you so much for sharing this code. I recently found a photograph of my 8 yr old son on a woman's website -- my son was photographed with a famous actor, and her website is devoted to "hot me." I was totally freaked out. Thankfully she removed my photo immediately -- but this code will help prevent future photo thefts. :)
isit works for every image put on the website or facebook also?
But people still can left click it and go the original image link and then copy the image. Can we protect that too so image are really unclickable (for good)? thanks
Thanx Friend this proved useful for me.thanx again !! :)
thnx
Worked seamlessly. Thanks
works great! thank you!
It works :) you are awesome!!! thank you!
Thank you! I am constantly filing DMCA complaints because people feel they can take whatever pictures they find on my blog. Watermark no deterrent enough. I'm all for making the job of these thives as hard as possible. Obviously nothing can stop a person from stealing, but I found out that many are ignorant of Copyrights, basic internet ettiquette, and in some cases I doubt they even are techsavy as I found a few that were hotlinked straight from my blog. Right click blocking prevents this from happening at least
wow amazing bro, thank you sooooooooooo much..! Love it from Sri Lanka
Thanks a lot mate! This is brilliant and bloody fantastic!
Post a Comment
We love to hear from you! Leave us a comment.
To ensure proper display, HTML/XML/Javascript need to be escaped first using this escape tool.