One of my customers wanted to prevent people from right-clicking on images on their website. That brought back memories of websites on GeoCities a decade ago. There are still so many ways around it that the attempt is almost useless. My favorite way was always to view the page source. It is also possible to disable JavaScript, use a website debugging plugin, or save the (complete) page to a directory on your harddrive. In the past, the popular method to stop image theft has been to make a JavaScript Alert() box pop up when the user right-clicked on a picture. This quickly makes the website look less professional. With Web 2.0 being so popular, there are better ways now to hide the context menu. Luke Breuer has a tutorial on how to replace the browser’s default with your own. After looking at his code, it looks like the code required to silently prevent right-clicking on images is surprisingly simple:
<script language="JavaScript" type="text/javascript">
function ContextHide(event) {
if (event == null)
event = window.event;
var target = (event.target != null) ? event.target : event.srcElement;
if (target.tagName.toLowerCase() == 'img')
return false;
}
document.body.oncontextmenu = ContextHide;
</script>
Note that I intentionally did not include any comments. Go read up on what all of this does. It works on Firefox 3, Internet Exploder 7, Safari 4 (Public Beta), and Google Chrome 2. It does not seem to work with Opera, even after enabling the ability for scripts to see right-click events (non-default setting). Enjoy.