Protect Images Using JavaScript

This technique uses JavaScript to disable right-clicking, but unlike most right-click disablers, it only affects images (not the rest of the page). Try right-clicking the image on the right to see what happens.

There are some things you need to understand about this technique:

Basically, disabling right-clicks is not generally recommended but we have provided the code anyway for those of you who are absolutely determined to use it.

Place this code in the page head:

<SCRIPT LANGUAGE="JavaScript">
function right(e) {
var msg = "right-clicking on images is not permitted.";
if (navigator.appName == 'Netscape' && e.which == 3) {
alert(msg);
return false;
}
if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
alert(msg);
return false;
}
else return true;
}

function trapclick()
{
if(document.images)
{
for(i=0;i<document.images.length;i++)
{
document.images[i].onmousedown = right;
document.images[i].onmouseup = right;
}
}
}
</SCRIPT>

Place this code in the body tag:

<BODY onLoad="trapclick()">