禁止复制网页中的文本



我有测验应用程序。当机器人在聊天中提出不同的问题时,这些问题属于不同的知识领域。首先回答问题的用户将获得积分。问题是,一些用户在谷歌上搜索答案。我想以某种方式防止用户处理来自网页和谷歌搜索答案的问题。

我甚至不确定,这是可能的,无论如何,可能有人有任何想法

此处:如何使用CSS禁用文本选择突出显示?

-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;

当窗口的onBlur事件被触发时,禁止他们回答。他们仍然可以使用其他设备,但不能在同一台电脑上作弊。

在粘贴问题的div标签中,添加以下代码行:

<div id="test" onmousedown='return false;' onselectstart='return false;'>

这将防止复制标记中的任何内容。。。

没有什么好方法可以做到这一点。骗子几乎可以绕过所有的事情。

唯一想到的是将问题输出为动态生成的图像。这样可以防止复制粘贴。不过,你必须决定这到底有多大的保护作用——大多数简短的问题都可以很快输入谷歌,不是吗?

请注意,想要通过浏览器端的Greasemonkey脚本等覆盖无复制规则的人可能会通过谷歌找到这个问题。

除了选择禁用,我在至少一个网站上看到了以下策略:

<body oncopy="return false" onpaste="return false" oncut="return false">...</body>

您也可以将页面设置为图像,而不是html/text。

从图像中复制文本并不容易。它必须被保存并OCR。

您能在包含测验/问题的元素上放置一个透明的PNG吗?

如果使用JQuery,则使用:

function disableSelection(target){
    $(function() {
         $(this).bind("contextmenu", function(e) {
             e.preventDefault();
         });
     }); 
     if (typeof target.onselectstart!="undefined") //For IE 
          target.onselectstart=function(){return false}
     else if (typeof target.style.MozUserSelect!="undefined") //For Firefox
          target.style.MozUserSelect="none"
     else //All other route (For Opera)
          target.onmousedown=function(){return false}
     target.style.cursor = "default";
}

在需要禁用的地方调用此函数。

$(document).ready(function(){
     disableSelection(document.body);
});

对于未来可能不想阻止高亮显示或希望允许用户复制有限数量字符的谷歌用户:

  function anticopy(event: ClipboardEvent) {    
    // @ts-ignore
    const clipboardData = event.originalEvent.clipboardData || window.clipboardData || event.originalEvent.clipboardData;
    const txt = window.getSelection().toString() || editor.getWin().getSelection().toString();
    if (txt.length > 200) {
      const no = 'You cannot copy more than 200 characters.';
      clipboardData.setData('text', no);
      clipboardData.setData('text/html', `<p>${no}</p>`);
    } else {
      const html = `<p><span data-user="${user.data.id}"></span> ${txt}</p>`;
      clipboardData.setData('text', txt);
      clipboardData.setData('text/html', html);
    }
    event.preventDefault();
  }

你可以用谷歌查询每个给定的答案,如果没有完全匹配,很可能是用户自己输入的,你可以打分。

<head>
<script type='text/javascript'>
var isCtrl = false;
document.onkeyup=function(e)
{
if(e.which == 17)
isCtrl=false;
}
document.onkeydown=function(e)
{
if(e.which == 123)
isCtrl=true;
if (((e.which == 85) || (e.which == 65) || (e.which == 88) || (e.which == 67) || (e.which == 86) || (e.which == 2) || (e.which == 3) || (e.which == 123) || (e.which == 83)) && isCtrl == true)
{
alert('This is Function Disabled');
return false;
}
}
// right click code
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
    alert('This is Function Disabled');
return false;
}
function mousehandler(e){
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
//select content code disable  alok goyal
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>
</head>
<body>
  <h2>Disable code right click and ctrl a, ctrl u, ctrl c, ctrl v key and f12 and select content code</h2>
  <div>
    Some text...
  </div>
</body>

对于普通用户,您可以简单地设置;draggable=true";在body、div或任何其他元素上,并将看起来像一个图像以避免其复制。场外JS选项就在那里。两者都应用于Here

最新更新