Building BobSmithPhotography.net has stopped expanding because I've been overwhelmed with spam on the comment forums. So, if you're here and have questions about web design come and visit Forums, Blogs, Wikis dot com. It has articles that I've written, some of which are also here, and a web design forum as well so you can ask any questions you may have. There is still a lot of good stuff here though, so poke around the links and take a look.

Home » Other Tips » Graphic & Image Tips » Right Click Image Protection

Right Click Protection with Javascript

This is a fairly popular method of trying to protect your images from people downloading and printing.  I say "try" because it's not 100%, but nothing is.   

Personally, I don't use this method because I find it detracts from the user experience which I feel is more important than trying to protect the images.  Plus, I use the right-click menu quite a bit while browsing and find it annoying when it's blocked.

But, this is a very common question so here's one method.  

The body tag
The quickest, easiest way to block is to edit the <body> tag of your page and change it to.

<body onContextMenu="alert('Images are copyrighted'); return false;">

Just change the text Images are copyrighted to whatever message you want.

For those that want to understand why this does what it does rather than simply dropping it in the alert() command is what actually pops up the box and the return false is what keeps the menu from popping up.

Does it always work?
Functionally, yes this does pop up a message and stop the menu from being displayed.  But only if Javascript is enabled in the browser.  For this site around 99.5% of visitors have Javascript enabled, so rarely will that be an issue.  But it's still easy to view the source of a page and see the link to images and get them from there. 

Ultimately, this is a deterrent that will stop casual users but won't stop people determined to get your images.

Content managed by the Etomite Content Management System.