通過javascript來實現:
oncontextmenu 右鍵菜單事件
onselectstart 選中網頁內容事件
oncopy 復制網頁內容事件
寫法1:
<script type="text/javascript">document.oncontextmenu = function(){return false;};</script>
寫法2: 也可以直接在<body>標簽上添加屬性,如:java代碼
<body οncοntextmenu="return false">
效果一樣。明白了上面的原理,也就找到了破解的方法,如下:在瀏覽器地址欄(或者 Ctrl + O)輸入以下代碼:
javascript:alert(document.onselectstart = document.οncοntextmenu= document.onmousedown = document.onkeydown = function(){return true;});
通過css中讓網頁禁止右鍵菜單的方法:
-webkit-touch-callout: none; /*系統(tǒng)默認菜單被禁用*/ -webkit-user-select: none; /*webkit瀏覽器*/ -khtml-user-select: none; /*早起瀏覽器*/ -moz-user-select: none; /*火狐瀏覽器*/ -ms-user-select: none; /*IE瀏覽器*/ user-select: none; /*用戶是否能夠選中文本*/
/*設置IOS頁面長按不可復制粘貼,但是IOS上出現input、textarea不能輸入,因此將使用-webkit-user-select:auto;*/
*{ -webkit-touch-callout:none; /*系統(tǒng)默認菜單被禁用*/ -webkit-user-select:none; /*webkit瀏覽器*/ -khtml-user-select:none; /*早期瀏覽器*/ -moz-user-select:none; /*火狐*/ -ms-user-select:none; /*IE10*/ user-select:none; } input,textarea { -webkit-user-select:auto; /*webkit瀏覽器*/ margin: 0px; padding: 0px; outline: none; }
如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網友會為你解答!! 點擊進入論壇