禁止鼠標右鍵、禁止全選、復制、粘貼;
oncontextmenu事件禁用右鍵菜單;
document.oncontextmenu = function(){ event.returnValue = false; }
//另一種 document.oncontextmenu = function(){ return false; } //直接在body上 <body oncontextmenu = "return false" ></body>
onselectstart事件禁用網頁上選取的內容;
document.onselectstart = function(){ event.returnValue = false; }
//另一種
document.onselectstart = function(){ return false; }
//直接在body上 <body onselectstart = "return false" ></body>
oncopy事件禁用復制;
document.oncopy = function(){ event.returnValue = false; }
//另一種
document.oncopy = function(){ return false; }
//直接在body上 <body oncopy = "return false" ></body>
甚至可以可以禁用鼠標事件
document.onmousedown = function(e){ if ( e.which == 2 ){// 鼠標滾輪的按下,滾動不觸發 return false; } if( e.which==3 ){// 鼠標右鍵 return false; } }
需要頁面禁止復制或者右鍵打開菜單的情況下,最好結合多種方法進行禁用
額外的寫一些關於禁用鍵盤按鍵的內容
document.onkeydown = function(){ if( event.ctrlKey ){ return false; } if ( event.altKey ){ return false; } if ( event.shiftKey ){ return false; } }