Disable Copying on a website

前端 未结 8 1149
礼貌的吻别
礼貌的吻别 2021-02-10 06:38

I know that it\'s impossible to thwart the world\'s most advanced minds, but I\'d like to put the slightest of barriers on my website to keep my students from copying text from

相关标签:
8条回答
  • 2021-02-10 07:15

    Selecting text, copy, the right click can be disabled on a web page easily using jQuery. Below is the simple jQuery code snippet which can do this task easily:

    <script type="text/javascript">
    // Disable right click on web page
    $("html").on("contextmenu",function(e){
        return false;
    });
    // Disable cut, copy and paste on web page
    $('html').bind('cut copy paste', function (e) {
         e.preventDefault();
    });
    </script>
    

    Source: Disable right click, copy, cut on web page using jQuery

    0 讨论(0)
  • 2021-02-10 07:16

    If you have your texts in particular divs, you could put a transparent div on top of those divs. Secondly, you could make all your protected text dynamic, and inject it into the divs from javascript where is would exist in a coded form -- that would defeat a 'view-source'.

    0 讨论(0)
  • 2021-02-10 07:18

    I would suggest you to use:

    <div oncopy="return false;">Here you have protected text</div>
    

    Support for this method could be found here: http://help.dottoro.com/ljwexqxl.php

    It is simple and in my opinion sufficient against regular users. To be honest there is no option to fully prevent copying text. One can always use for example Chrome Developer Tools and copy even dynamically loaded text from there.

    For more effective protection you should place oncopy in <body> tag because otherwise it is possible to copy text by starting selection from outer <div>.

    0 讨论(0)
  • 2021-02-10 07:21

    To achieve that you need to block mouse click and context menu click on your webpage.

    Here is a sample code:

    <script language="JavaScript1.2">
        var msgpopup="COPYING CONTENT IS PROHIBITED";
        function handle(){
              if(toShowMessage== "1") alert(message);
                  if(closeSelf== "1") self.close();
                  return false;
        }
        function mouseDown() {
             if (event.button == "2" || event.button == "3"){handle();}
        }
        function mouseUp(e) {
             //if (document.layers || (document.getElementById && !document.all)){
                  if (e.which == "2" || e.which == "3"){ handle();}
             //}
        }
        document.onmousedown=mouseDown;
        document.onmouseup=mouseUp;
        document.oncontextmenu=new Function("alert(msgpopup);return false")
        </script>
    
    0 讨论(0)
  • 2021-02-10 07:24

    Its some how daunting to create a function that would do that, what you should target is, clearing the clipboard so even if, the user press Ctrl + C, nothing is copied into the clipboard, a simple function like this should do the trick :

    <script language="javascript">
        function clearData(){
            window.clipboardData.setData('text','') 
        }
        function cldata(){
            if(clipboardData){
                clipboardData.clearData();
            }
        }
        setInterval("cldata();", 1000);
    </script>
    
    
    <body ondragstart="return false;" onselectstart="return false;"  oncontextmenu="return false;" onload="clearData();" onblur="clearData();">
    

    although this can still be defeated....

    0 讨论(0)
  • 2021-02-10 07:27
    <script type="text/javascript" language="javascript">
    
         $(function() {
    
                $(this).bind("contextmenu", function(e) {
    
                    e.preventDefault();
    
                });
    
            }); 
    </script>
    <script type="text/JavaScript"> 
    function killCopy(e){ return false } 
    function reEnable(){ return true } 
    document.onselectstart=new Function ("return false"); 
    if (window.sidebar)
    { document.onmousedown=killCopy; 
    document.onclick=reEnable; } 
    </script>
    

    //By using above code you right click will be disabled as well as no one can copy your page content

    0 讨论(0)
提交回复
热议问题