Home >Web Front-end >JS Tutorial >js disable key presses and mouse clicks

js disable key presses and mouse clicks

PHPz
PHPzforward
2016-05-16 19:15:101448browse

Disable keyboard keys through the document.onkeydown event;

Disable mouse clicks through the document.onmousedown event;

function EventOper(){
	if(event.keyCode==8){
		event.keyCode=0;
		event.returnValue=false;
		alert("不允许使用退格键");
	}
	if(event.keyCode==13){
		event.keyCode=0;
		event.returnValue=false;
		alert("不允许使用回车键");
	}
	if(event.keyCode==116){
		event.keyCode=0;
		event.returnValue=false;
		alert("不允许使用F5键");
	}
	if(event.ctrlKey){		
		event.returnValue=false;
		alert("不允许使用CTRL键");
	}

	if((event.altKey)&&(event.keyCode==78)){		
		event.returnValue=false;
		alert("不允许使用ALT+N键");
	}
	if((event.shiftKey)&&(event.keyCode==78)){		
		event.returnValue=false;
		alert("不允许使用SHIFT+N键");
	}
	
	
}

function rightKey(){
	if(event.button==2){
		event.returnValue=false;
		alert("禁用鼠标右键");
	}
}
document.onkeydown=EventOper;
document.onmousedown=rightKey;

For more related tutorials, please visit JavaScript video tutorial

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete