Disable Copying on a website

前端 未结 8 1150
礼貌的吻别
礼貌的吻别 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:29

    A simple and valid solution - bind to the 'copy' event and prevent it. You can also set what text will be copied (and later pasted by the user).

    document.addEventListener('copy', function (e){
        e.preventDefault();
        e.clipboardData.setData("text/plain", "Do not copy this site's content!");
    })
    
    0 讨论(0)
  • 2021-02-10 07:31

    Just add the following code right before closing </HEAD> tag of your web page:

    <script>
        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>
    
    0 讨论(0)
提交回复
热议问题