开发者社区 问答 正文

360doc个人图书馆里的禁止复制是怎么实现的?

选择内容后右键选复制都不可以。

展开
收起
杨冬芳 2016-06-14 16:05:05 3881 分享 版权
2 条回答
写回答
取消 提交回答
  • 阿里云论坛版主,QQ 1978638808
    <BODY oncontextmenu="return false" onselectstart="return false" 
    ondragstart="return false" onbeforecopy="return false" oncopy=document.selection.empty() onselect=document.selection.empty()> 
    
    -----------------------------------------------
    
    防止复制的js
    
    -----------------------------------------------
    
    <SCRIPT language=JavaScript1.2>
    function disableselect(e){
    return false}
    function reEnable(){return true
    }
    file://if IE4+
    document.onselectstart=new Function ("return false")
    file://if NS6
    if (window.sidebar){
    document.onmousedown=disableselect
    document.onclick=reEnable
    }
    </SCRIPT>
    <SCRIPT language=JavaScript type=text/JavaScript>
    <!--
    function MM_reloadPage(init) {    //reloads the window if Nav4 resized
        if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
          document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
        else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);
    //-->
    </SCRIPT>
    
    -------------------------------------------------------
    
    防止下载的js
    
    -------------------------------------------------------
    <noscript><iframe src=""></iframe></noscript>
    
    --------------------------------------------------------
    
    下面是防止右键的js:
    
    --------------------------------------------------------
    
    <script language="JavaScript">
    
    <!--
    if (window.Event) 
    document.captureEvents(Event.MOUSEUP); 
    function nocontextmenu() {
    event.cancelBubble = true
    event.returnValue = false;
    return false;
    }
    function norightclick(e) {
    if (window.Event){
       if (e.which == 2 || e.which == 3)
       return false;
    }else{
       if (event.button == 2 || event.button == 3){
           event.cancelBubble = true
        event.returnValue = false;
           return false;
        }
    }
    }
    
    document.oncontextmenu = nocontextmenu; // for IE5+
    document.onmousedown = norightclick; // for all others
    //-->
    </script>
    2019-07-17 19:37:58
    赞同 展开评论
  • IT从业

    screenshot

    console.log(document.getElementsByTagName("body")[0].oncopy)

    function() {
        var CurUserNameCookiescgcg = getCookie("LoginName");
        if (CurUserNameCookiescgcg == "" || CurUserNameCookiescgcg == null) {
            getJSON("http://www.360doc.com/ajax/GetLoginForm20130912.ashx?ArtID=" + ArticleID + "&type=2&arttype=" + CurArtType + "&jsoncallback=?",
            function(responseText) {
                document.getElementById('LayerLogin').innerHTML = responseText.html;
                showBg("dialog", "dialog_content", "2")
            });
            return false
        } else {
            var selhtml = "";
            var selection;
            if (window.getSelection) {
                selection = window.getSelection();
                if (selection != null) {
                    selhtml = selection.toString()
                }
            } else if (document.selection) {
                selection = document.selection.createRange();
                if (selection != null) {
                    selhtml = selection.text
                }
            }
            if (selhtml.length > 200) {
                var CurUserNameCookiescgcg = getCookie("LoginName");
                if (CurUserNameCookiescgcg == "" || CurUserNameCookiescgcg == null) {
                    alert("提示:点击标题下方的\"我也要收藏\"可将文章保存到\"我的个人图书馆\"中,然后可以拷贝自己文章的内容!\n\n您在网上读到好文章时想拷贝并保存到自己的电脑中吗?现在您不用再这样做了!\n\n360doc个人图书馆----知识管理  智交天下!\n保存:保存网上看到的及自己电脑中的文章资料\n管理:文件夹分类管理,百度式搜索查找\n分享:大众分享,好友分享,圈子分享")
                } else {
                    alert("提示:点击标题下方的“我也要收藏”可将文章保存到我的图书馆,然后可以拷贝自己文章的内容!")
                }
                return false
            } else {
                return true
            }
        }
    }
    
    2019-07-17 19:37:58
    赞同 展开评论
问答地址: