Simple, easy to use javascript to block copy and paste (context menu) from specific parts of a webpage

At my work, I often spend time changing hot-linked images to screw with our lazy competitors (god I wish prostores would give its users access to .htaccess!). I’ve used several methods to make our listings a little bit more of a pain on the ass to copy, but once they’re on ebay, all bets are off. There’s one of our competitors that just uses the good old copy paste method of generating listings. I’ve changed hot-linked images on him, it seems he never notices. Of course if we’re editing and posting stock photos from a manufacturer, we have no copyright claim on the image. I’ve also thought of using one of the many scripts that disable right clicking or selecting anywhere on a page. These would probably add enough work that he would lay off, but ebay thoroughly disapproves of anything that changes the functionality of their site. A great example of one of these can be found at Rainbow Arch:

<SCRIPT TYPE="text/javascript"> 
<!-- 
//Disable right click script 
//visit http://www.rainbow.arch.scriptmania.com/scripts/ 
var message="Sorry, right-click has been disabled"; 
/////////////////////////////////// 
function clickIE() {if (document.all) {(message);return false;}} 
function clickNS(e) {if 
(document.layers||(document.getElementById&amp;&amp;!document.all)) { 
if (e.which==2||e.which==3) {(message);return false;}}} 
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} 
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} 
document.oncontextmenu=new Function("return false") 
// --> 
</SCRIPT>

and…

<SCRIPT TYPE="text/javascript"> 
<!-- 
//Disable select-text script (IE4+, NS6+)
//visit http://www.rainbow.arch.scriptmania.com/scripts/ 
/////////////////////////////////// 
function disableselect(e){
return false
} 
function reEnable(){
return true
} 
//if IE4+
document.onselectstart=new Function ("return false") 
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
// -->
</SCRIPT>

An excellent solution, but it would eventually get us on eBay’s shitlist.

I recently came across a much more elegant solution… I came across the ‘oncontextmenu’ event thanks to an article on about.com. This method is so much more efficient, as the context menu really is what you’re trying to block with a ‘no right click’ script. The real beauty of this method, is that it can be used on individual elements instead of the entire page! All of my listing templates use a main wrapper for styling, so all that needs to be done is add the following to the main wrapper tag:

oncontextmenu="return false;"

Easy! This still allows text selection and [ctrl]+c to copy, but is vastly more effective than background image swaps and massive no right click scripts. Drag and drop probably still works the same, but there’s not much to be done about that. It’s one more bit of work that our lazy-ass competitors will have to deal with though!

One thought on “Simple, easy to use javascript to block copy and paste (context menu) from specific parts of a webpage

  1. Watermarks… and banning them if they try to use it anyways work? I’m not a big seller so I’m not sure if eBay stonewalls/delays banning of said users/auctions. Seems changing functionality of the browser is the wrong way to go about this. After all, they have to have bank accounts to sell! This isn’t like P2P networks where your service provider (in this case eBay) has no idea who they are.

    Even if someone puts a bar over the (centered) watermark and places their own text there, it’s pretty easy to prove copyright infringement. There are also (free) tools that automatically apply invisible watermarks to an entire folder full of images. I always use my own photos so the stock image issue never applies to me.

Comments are closed.