Saturday, September 13, 2008

Disable Right Click using Javascript

Disable the Right click, when the user tried to get the view source or any other operation we can restrict the right click operation using this code.

< script language=JavaScript>
< !--

//Disable right mouse click Script

var message="Function Disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")

// -->
< /script>


More info:
1. http://www.dynamicdrive.com
2. http://www.sitepoint.com/article/dont-disable-right-click/
3. http://www.angelfire.com/fl5/html-tutorial/rclickcode.htm

No comments:

Popular Posts