zoukankan      html  css  js  c++  java
  • HTML 禁止复制文字

            因为本人平时喜欢看网络小说,但是喜欢看的文通过正经网站或者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.禁止选中文字 

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

    *{
        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)

    5.禁止网页另存为:在<body>后面加入以下代码: 

    <noscript> 
        <iframe src="*.htm"></iframe> 
    </noscript>  

    至此,已经限制了大部分的复制功能,但是还不能彻底禁止,更完善的方法还需学习整理。

    原文:https://blog.csdn.net/baidu_23275675/article/details/83302425

    原文:https://www.cnblogs.com/vickylinj/p/11913355.html

  • 相关阅读:
    AGC037F Counting of Subarrays
    AGC025F Addition and Andition
    CF506C Mr. Kitayuta vs. Bamboos
    AGC032D Rotation Sort
    ARC101F Robots and Exits
    AGC032E Modulo Pairing
    CF559E Gerald and Path
    CF685C Optimal Point
    聊聊Mysql索引和redis跳表
    什么是线程安全
  • 原文地址:https://www.cnblogs.com/bluealine/p/12516724.html
Copyright © 2011-2022 走看看