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

js disable key presses and mouse clicks

PHPz
Release: 2018-10-10 15:55:07
forward
1419 people have browsed it

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;
Copy after login

For more related tutorials, please visit JavaScript video tutorial

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template