1.禁用选中和右键:

    在标签中添加以下代码:

    1. οncοntextmenu='return false' 禁止右键
    2. οndragstart='return false' 禁止拖动
    3. onselectstart ='return false' 禁止选中
    4. οnselect='document.selection.empty()' 禁止选中
    5. οncοpy='document.selection.empty()' 禁止复制
    6. onbeforecopy='return false' 禁止复制
    7. οnmοuseup='document.selection.empty()'

    如下:

    1. <body
    2. leftmargin=0
    3. topmargin=0
    4. οncοntextmenu='return false'
    5. οndragstart='return false'
    6. onselectstart ='return false'
    7. οnselect='document.selection.empty()'
    8. οncοpy='document.selection.empty()'
    9. onbeforecopy='return false'
    10. οnmοuseup='document.selection.empty()'
    11. />

    2.禁止网页另存为:在后面加入以下代码:

    1. <noscript>
    2. <iframe src="*.htm"></iframe>
    3. </noscript>

    这时在电脑端已经无法选择复制,但是在移动端还可以选中复制,再添加以下css代码用来禁止选中文字。

    3.禁止选中文字

    1. *{
    2. moz-user-select: -moz-none;
    3. -moz-user-select: none;
    4. -o-user-select:none;
    5. -khtml-user-select:none;
    6. -webkit-user-select:none;
    7. -ms-user-select:none;
    8. user-select:none;
    9. }

    这时正常的选择复制都已经被禁用但是还可以用浏览器的查看源码和调试工具来直接从代码中复制内容。

    4.禁用F12按键

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

    5.禁用调试工具

    1. var threshold = 160; // 打开控制台的宽或高阈值
    2. // 每秒检查一次
    3. var check = setInterval(function() {
    4. if (window.outerWidth - window.innerWidth > threshold ||
    5. window.outerHeight - window.innerHeight > threshold) {
    6. // 如果打开控制台,则刷新页面
    7. window.location.reload();
    8. }
    9. }, 1000);