Thursday, April 10, 2008

JS code to disable right click and refresh button

document.onmousedown="if (event.button==2) return false";
document.oncontextmenu=new Function("return false");//disable right click

document.onkeydown = showDown;

function showDown(evt)
{
evt = (evt)? evt : ((event)? event : null);
if (evt) {
if (event.keycode == 8 && (event.srcElement.type!= "text" && event.srcElement.type!= "textarea" && event.srcElement.type!= "password")) {
// When backspace is pressed but not in form element
cancelKey(evt);
}
else if (event.keycode == 116) {
// When F5 is pressed
alert("asdfasfdasd");
cancelKey(evt);
}
else if (event.keycode == 122) {
// When F11 is pressed
cancelKey(evt);
}
else if (event.ctrlKey && (event.keycode == 78 ¦¦ event.keycode == 82)) {
// When ctrl is pressed with R or N
cancelKey(evt);
}
else if (event.altKey && event.keycode==37 ) {
// stop Alt left cursor
return false;
}
}
}

function cancelKey(evt) {
if (evt.preventDefault) {
evt.preventDefault();
return false;
}
else {
evt.keycode = 0;
evt.returnValue = false;
}
}

No comments:

PC Magazine Tips and Solutions

PC World: Latest Technology News

PCWorld.com - Most Popular Downloads of the Week