[HTML,JS禁止鼠標右鍵、禁止全選、復制、粘貼的方法]

[HTML,JS禁止鼠標右鍵、禁止全選、復制、粘貼的方法]
禁止鼠標右鍵、禁止全選、復制、粘貼;
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; }}關鍵就在

oncontextmenu='return false'  ondragstart='return false'   onselectstart ='return false'   onselect='document.selection.empty()'   oncopy='document.selection.empty()'   onbeforecopy='return false'   onmouseup='document.selection.empty()'
一個更簡單的方法就是在<body>中加入如下的代碼,這樣鼠標的左右鍵都失效了. topmargin="0" oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()" 1.禁止網頁另存為:在<body>后面加入以下代碼: <noscript> <iframe src="*.htm"></iframe> </noscript> 2.禁止網頁內容復制.粘貼:在<body>中加入以下代碼: <body onmousemove=/HideMenu()/ oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">

轉自:(http://www.cnblogs.com/happiness-mumu/p/6269465.html)

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,837評論 18 139
  • 事件源對象 event.srcElement.tagName event.srcElement.type 捕獲釋放...
    孤魂草閱讀 902評論 0 0
  • 單例模式 適用場景:可能會在場景中使用到對象,但只有一個實例,加載時并不主動創建,需要時才創建 最常見的單例模式,...
    Obeing閱讀 2,092評論 1 10
  • 個人博客:https://yeaseonzhang.github.io 花了半個多月的時間,終于又把“JS紅寶書”...
    Yeaseon閱讀 1,787評論 2 23
  • 數組: 下面創建一個數組,用于存儲5個人的數學成績。 var myarray=new Array();//創建一個...
    無極之刃閱讀 369評論 0 0