1.禁用选中和右键:
在标签中添加以下代码:
ο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()'
如下:
<bodyleftmargin=0topmargin=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.禁止网页另存为:在后面加入以下代码:
<noscript><iframe src="*.htm"></iframe></noscript>
这时在电脑端已经无法选择复制,但是在移动端还可以选中复制,再添加以下css代码用来禁止选中文字。
3.禁止选中文字
*{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;}
这时正常的选择复制都已经被禁用但是还可以用浏览器的查看源码和调试工具来直接从代码中复制内容。
4.禁用F12按键
//禁用F12window.onkeydown = window.onkeyup = window.onkeypress = function (event) {// 判断是否按下F12,F12键码为123if (event.keyCode == 123) {event.preventDefault(); // 阻止默认事件行为window.event.returnValue = false;}}
5.禁用调试工具
var threshold = 160; // 打开控制台的宽或高阈值// 每秒检查一次var check = setInterval(function() {if (window.outerWidth - window.innerWidth > threshold ||window.outerHeight - window.innerHeight > threshold) {// 如果打开控制台,则刷新页面window.location.reload();}}, 1000);
