Disable right click context menu on images

disable image right click 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:

disable image context menu

  • 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!

58 comments to "Disable right click context menu on images"

Jack May 15, 2012 at 12:05 PM    

nice tips, thank so much

Gina May 15, 2012 at 7:28 PM    

Will that prevent folks from putting your pics on Pinterest?

Gilbert Canda May 15, 2012 at 7:33 PM    

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.

bryanliem2020@yahoo.com,  May 15, 2012 at 7:34 PM    

Thank for share this code.
How to use this code with "back to top" by right click

Rosie@leavesnbloom May 16, 2012 at 1:17 AM    

I have been looking for a hack like this just for images - thankyou so so much Greenlava........perfect timing!

hermadut May 16, 2012 at 12:14 PM    

love the tips.. thanks for sharing

Maya May 16, 2012 at 1:11 PM    

I was actually wondering why on some blogs my right mouse button is disabled. Now I know! Thanks for sharing!

Mason disick May 16, 2012 at 1:40 PM    

thanks Greenlava, now i can save my self-drawing images.

Greenlava May 16, 2012 at 4:05 PM    

@Gina
No it won't prevent (Pinterest) pinning.

Belajar NgeBlog May 16, 2012 at 11:42 PM    

oke. its works.

Lemonade Media (Web development Beijing) May 18, 2012 at 7:53 PM    

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.

Services of app development May 22, 2012 at 3:00 PM    

But even if you disable the right click you pic may be "borrowed" from the google pic search.

Mister Leaf May 22, 2012 at 8:32 PM    

Very nice info.
Anyway, if people really want to steal, they'll do it.
Still back to the root, the mentality of people.

wesmob May 26, 2012 at 1:14 AM    

Good Script

Blogger Tips May 28, 2012 at 6:38 PM    

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?

irsah May 29, 2012 at 3:45 AM    

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.

Damilare Bakare May 31, 2012 at 8:37 PM    

nice article,

Jasmine June 1, 2012 at 2:30 AM    

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.

bibliophile21 June 4, 2012 at 5:57 AM    

Good to know. Obviously people will take something if they really want to, but why make it any easier for them?

Sai Krish June 5, 2012 at 11:48 AM    

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

gamepoint amd June 8, 2012 at 10:56 PM    

when i delete the line or comment the line, the script will not work..weird

Greenlava June 9, 2012 at 1:44 PM    

@Sai Krish
There is no mistake. You can do it either way, before or after.

Prayas June 11, 2012 at 11:40 AM    

Thanks for this it is really helpfull

NaSaSrKr June 19, 2012 at 10:36 AM    

@Greenlava
Hoo Its works before and after the /head tag
Thank U
--urs NaSaSrKr(alias Sai Krish)

casey micvile June 29, 2012 at 6:55 PM    

thanks for sharing information.

josie chapman August 24, 2012 at 9:32 PM    

Thanks so much for your help.

Laura Dmguez September 7, 2012 at 5:41 AM    

Thanks!! This is exactly what I was looking for :D

4polinka September 15, 2012 at 10:15 PM    

what a great trick! works perfect
thank u

Ramakrishna @ Techzost October 17, 2012 at 9:09 PM    

thanks BS. This trick is really awesome. :-O

worldwebsurfers.com October 30, 2012 at 6:13 AM    

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.

hacking tricks November 2, 2012 at 11:01 PM    

thank you so muck i like it thank for sharing it

Sang Biru December 12, 2012 at 8:52 PM    

Nice tips.....work like a magic on my blog....tq man:)

Loraine Ira Amorin Ompad December 21, 2012 at 10:09 PM    

Thank you so much :)

raman bathina February 9, 2013 at 2:21 PM    

Nice trick bro but it is easily breakable through firefox without using any code,extensions,plug-ins or even software.

Anonymous,  February 12, 2013 at 2:04 AM    

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.

Maia March 8, 2013 at 9:49 PM    

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?

Greenlava March 10, 2013 at 6:56 PM    

@Maia
You need to delete line 11 as well.

Manish Dhabai April 13, 2013 at 1:55 PM    

Thanks. it works. i use this because someone is copy my pictures to his blog.

Alisha Smith Watkins May 14, 2013 at 8:53 AM    

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

jabbar June 11, 2013 at 1:15 PM    

Very nice coding, and how can i change the message title ?

Greenlava June 13, 2013 at 5:04 PM    

@jabbar
You can't. It's a browser feature.

jayachandra June 20, 2013 at 3:02 PM    

I am looking for this to control the copy of Images. Thanks a lot. --Jay

Anonymous,  August 7, 2013 at 4:05 PM    

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.

Konstantin August 16, 2013 at 5:25 PM    

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.

Dafilla,  August 19, 2013 at 7:06 PM    

Great script.

Anonymous,  August 20, 2013 at 6:06 PM    

For Wordpress sites I would recommend the WPCCP plugin. This works amazingly well ! http://wordpress.org/plugins/wp-content-copy-protection/

Jessica August 29, 2013 at 8:36 PM    

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. :)

Ayanthi De Silva October 3, 2013 at 12:04 AM    

thanks a lot

usman tariq January 24, 2014 at 12:59 AM    

Wow Gr8 Trick Really Extraordinary is that trick thanks admin Nixe Article >3

Disable Right Click on Blogspot/Website

Anonymous,  February 7, 2014 at 2:08 PM    

isit works for every image put on the website or facebook also?

she,  February 27, 2014 at 11:16 AM    

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

Anonymous,  February 28, 2014 at 12:22 PM    

Thanx Friend this proved useful for me.thanx again !! :)

Anindya Kumar March 7, 2014 at 4:02 AM    

thnx

mattmasha April 23, 2014 at 2:12 AM    

Worked seamlessly. Thanks

sharon loh August 18, 2014 at 10:26 AM    

works great! thank you!

RambleOn aka pam September 18, 2014 at 1:30 AM    

It works :) you are awesome!!! thank you!

cynthia haller November 23, 2014 at 12:22 PM    

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

sinhala wala November 26, 2014 at 2:44 AM    

wow amazing bro, thank you sooooooooooo much..! Love it from Sri Lanka

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.

Click to go to top Click to comment