Wednesday, April 25, 2012

Disabling right click option using javascript

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()">

No comments:

Post a Comment