因為本人平時喜歡看網絡小說,但是喜歡看的文通過正經網站或者app都需要收費,讓人很是不爽,所以...總之,百度網盤上資源很多。但是問題來了,這些資源肯定不會是作者自己流出的,也不應該是網站或app流出的,更不可能是讀者手打的。所以,最大的可能就是上網站復制的。。。所以不明白為什么網站要允許復制。下面是禁止復制文字的實現方式:
1.禁用選中和右鍵:
在<body>標簽中添加以下代碼:
ο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 leftmargin=0 topmargin=0 ο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()'>
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)
原文:https://blog.csdn.net/baidu_23275675/article/details/83302425