首頁  >  文章  >  web前端  >  html如何禁止複製文字

html如何禁止複製文字

coldplay.xixi
coldplay.xixi原創
2021-04-27 16:10:359021瀏覽

html禁止複製文字的方法:1、停用選取和右鍵;2、禁止選取文字;3、停用F12按鍵;4、停用偵錯工具。

html如何禁止複製文字

本教學操作環境:windows7系統、html5版,DELL G3電腦。

html禁止複製文字的方法:

1、停用選取和右鍵:

在6c04bd5ca3fcae76e30b72ad730ca86d標籤中新增以下程式碼:

οncοntextmenu='return false'    //禁止右鍵

οndragstart='return false'    //禁止拖曳

onselectstart ='return false'    //禁止拖曳

onselectstart ='return false'    //禁止禁止禁止禁止禁止禁止禁止禁止禁止使用選取

οnselect='document.selection.empty()'    //禁止選取

οncοpy='document.selection.empty()'    //禁止複製

onbeforecopy ='return false'   // 禁止複製

#οnmοuseup='document.selection.empty()' 

<body leftmargin=0 topmargin=0 οncοntextmenu=&#39;return false&#39; οndragstart=&#39;return false&#39; onselectstart =&#39;return false&#39; οnselect=&#39;document.selection.empty()&#39; οncοpy=&#39;document.selection.empty()&#39; onbeforecopy=&#39;return false&#39; οnmοuseup=&#39;document.selection.empty()&#39;>

#2、禁止選取文字 

#
*{
    moz-user-select: -moz-none;
    -moz-user-select: none;
    -o-user-select:none;
    -khtml-user-select:none;
    -webkit-user-select:none;
    -ms-user-select:none;
    user-select:none;
}

這時正常的選擇複製都已經被停用但是如果是程式設計師還知道可以用瀏覽器的檢視原始碼和偵錯工具來直接從程式碼複製內容。所以:

 

3、停用F12按鍵 

//禁用F12
window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
    // 判断是否按下F12,F12键码为123
    if (event.keyCode == 123) {
    event.preventDefault(); // 阻止默认事件行为
    window.event.returnValue = false;
    }
}

 

4、停用偵錯工具 

var threshold = 160; // 打开控制台的宽或高阈值
// 每秒检查一次
var check = setInterval(function() {
    if (window.outerWidth - window.innerWidth > threshold || 
        window.outerHeight - window.innerHeight > threshold) {
        // 如果打开控制台,则刷新页面
        window.location.reload();
    }
}, 1000)
相關學習推薦:

html影片教學
######

以上是html如何禁止複製文字的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn