views:

727

answers:

3

Hello,

I'm running an Asian e-commerce site where users post images of their products. Is there a way to disable right click for only 1 specific image on the page?

E.g. When viewing a product, there is a large image, and then some thumbnails of the product. When trying to right click on the large image, I want to disable right click, but if they try to right click on the thumbnails, I don't want to have right click disabled.

Thanks

ps - I fully understand the usability reasons why NOT to disable right-click, but copyright and image theft in Asia is a much larger problem than in North American countries. Plus, this is more for the seller peace-of-mind than actually protecting the content.

+4  A: 

Stopping people altogether is futile, however, my preferred way to at least make it slightly more difficult is to place a div over the top of the image.

<div id="image-container" style="postion: relative;">
   <img src="" alt="" />
   <div style="width: 100%; height: 100%; position: absolute; top: 0; left: 0"></div>
</div>

Play around with it to get what you want. To make it seem more semantic, you could place the text in the empty div 'Image is copyright' and then do text-indent: -9999px on it. I often try and turn an empty element into something semantic.

In saying that, my favourite way to bypass people that do this (e.g. eBay) is with the plugin Nuke Anything Enhanced for Firefox. Using the div over the image trick would take me approx 2 more seconds to bypass.

alex
Hi Alex,I tried your div container method but was having trouble getting it to work. Either way thanks for the suggestion :)
justinl
A: 

If you publish an image on the web there's no foolproof way to prevent somebody from saving a copy. It has to be sent over the wire to be displayed, and a determined user can intercept it with tools like Wireshark or Fiddler or any browser debugging framework such as Firebug, even if you find a way to disable right-click and drag-drop to the desktop.

You can make is very slightly more difficult, but the effort isn't worth it, IMHO.

Jim Garrison
I personally understand your view, but it's just... completely different mindset in Asia. Completely different culture which I argued to death over the website owners until they convinced me that just being able to say "ya, you can't right click" will give people peace of mind. Also, the Facebook of Asia doesn't have right click enabled. It's just the norm.
justinl
Is the print screen button disabled in Asia aswell? There is a term for this you know? It´s called 'Security through obscurity' and the only proved impact it has is disgruntled users. The people that really want to 'steal' the images will do so anyway. It´s even probable that some people that wouldn´t steal them in the first place will do so just for the sake of proving a point. And remember: doing work for customers of the Minas Morgul is considered harmful ;)
anddoutoi
+3  A: 

Although it's not W3C compliant, oncontextmenu="return false;" as an attribute should do exact what you want.

Steven Xu
This will still make it very easy for someone to bypass. A more robust solution would be to deliver the copyrighted images manually (store the image as a local file and redirect all requests for the images to a handler that does a rights check and at best returns binaries for the image). Coming up with more secure ways do this aren't hard, but take some creativity. Jigsaw your image by breaking it into parts and using CSS to piece them together. Deliver your images using Flash or like technology.At the end of the day, remember that anything that you can take a screenshot of can be stolen.
Steven Xu
Thanks Steven. Ya I understand it's so easy to bypass almost all of these Javascript "content protection" methods. I just needed something simple to make the customers happy and this oncontextmenu attribute has done the trick. thank you!
justinl
Most browsers can override this in the browser settings so it is a waste.
epascarello