禁止鼠標右鍵、禁止全選、複製、粘貼;
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;
}
以上三種事件,如果只想單純的禁用鼠標右鍵,和複製粘貼,還可以將它們直接寫到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;
}
}