Thursday, October 9, 2008

How to disable Right Click using Javascript?

Just add the below script in ur page..

var isnn,isie

if(navigator.appName=='Microsoft Internet Explorer') //check the browser
{ isie=true }

if(navigator.appName=='Netscape')
{ isnn=true }
function key(k)
{
if(isie) {
if(event.keyCode==17 || event.keyCode==18 || event.keyCode==93) {
alert("Sorry, you do not have permission to press this key.")
return false;
}
}

if(isnn){
alert("Sorry, you do not have permission to press this key.")
return false; }
}
document.oncontextmenu = function(){return false}
if(document.layers) {
window.captureEvents(Event.MOUSEDOWN);
window.onmousedown = function(e){
if(e.target==document)return false;
}
}
else {
document.onmousedown = function(){return false}
document.onkeydown=key;
}

No comments: