August 11, 2009

Disable Right Click On Images.

Many people wants that there photo's or images are not to be copied by other persons which are web. So here is solution which can disable right click on Images.





The Following script is used to Disable the right click on all Images which are present on your site.

If you are working on Sharepoint site place this script on MasterPage, Otherwise on page on which you want to disable right click on images. But It will disable right click on all the Images for site/page.

<script language="JavaScript">

var clickmessage="Right click disabled on images!"
function disableclick(e)
{
if (document.all)
{
if (event.button==2event.button==3)
{
if (event.srcElement.tagName=="IMG")
{
alert(clickmessage);
return false;
}
}
}
else if (document.layers)
{
if (e.which == 3)
{
alert(clickmessage);
return false;
}
}
else if (document.getElementById)
{
if (e.which==3&&e.target.tagName=="IMG")
{
alert(clickmessage)
return false
}
}
}

function associateimages()
{
for(i=0;idocument.images[i].onmousedown=disableclick;
}

if (document.all)
document.onmousedown=disableclick
else if (document.getElementById)
document.onmouseup=disableclick
else if (document.layers)
associateimages()
</script>

No comments: