禁用鼠标
禁止鼠标右键、禁止全选、复制、粘贴;
禁用右键菜单
oncontextmenu事件js代码:
document.oncontextmenu = function(){
event.returnValue = false;
}
// 或者直接返回整个事件
document.oncontextmenu = function(){
return false;
}
禁用网页上选取的内容
onselectstart事件js代码:
document.onselectstart = function(){
event.returnValue = false;
}
// 或者直接返回整个事件
document.onselectstart = function(){
return false;
}
禁用复制
oncopy事件js代码:
document.oncopy = function(){
event.returnValue = false;
}
// 或者直接返回整个事件
document.oncopy = function(){
return false;
}
直接操作body标签
以上都是通过js进行禁用,如果只想单纯的禁用鼠标右键、和复制粘贴,还可以将它们直接写到HTML中的body上面
<body oncontextmenu = "return false" ></body>
<body onselectstart = "return false" ></body>
<body oncopy = "return false" ></body>
只保留鼠标左键
document.onmousedown = function(e){
if ( e.which == 2 ){// 鼠标滚轮的按下,滚动不触发
return false;
}
if( e.which==3 ){// 鼠标右键
return false;
}
}
禁用键盘
禁用键盘中的ctrl、alt、shift
document.onkeydown = function(){
if( event.ctrlKey ){
return false;
}
if ( event.altKey ){
return false;
}
if ( event.shiftKey ){
return false;
}
}