日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

HTML,JS禁止鼠标右键、禁止全选、复制、粘贴的方法

發布時間:2024/9/20 HTML 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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; } }

關鍵就在??

  οncοntextmenu='return false'
  οndragstart='return false'?
  onselectstart ='return false'?
  οnselect='document.selection.empty()'?
  οncοpy='document.selection.empty()'?
  onbeforecopy='return false'?
  οnmοuseup='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()">

總結

以上是生活随笔為你收集整理的HTML,JS禁止鼠标右键、禁止全选、复制、粘贴的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。