Disable Copying on a website

前端 未结 8 1183
礼貌的吻别
礼貌的吻别 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!");
    })
    

提交回复
热议问题