前端禁止鼠標右鍵、禁止全選、復制、粘貼


禁止鼠標右鍵、禁止全選、復制、粘貼;

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;
    }
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM