Prevent copying text in web-page

HtmlCopy PasteCopy Protection

Html Problem Overview


I've got quiz application. Where robot ask different questions in chat, this questions belong to different areas of knowledges. User that answered question first, receive points. The problem is, that some users googling answers. I want somehow prevent users from coping question from web page and googling answers.

I'm not even sure, that this is possible, anyway probably someone got any ideas

Html Solutions


Solution 1 - Html

Here: https://stackoverflow.com/questions/826782/css-rule-to-disable-text-selection-highlighting

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

Disallow them from being able to answer when the window's onBlur event is fired. They can still use other devices, but they won't be able to cheat on the same computer.

Solution 2 - Html

In your div tag where you paste your question, add the following line of code:

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

This will prevent copying of anything that is within the tags...

Solution 3 - Html

There is no good way to do this. A cheater will be able to work around pretty much everything.

The only thing that comes to mind is to output the questions as dynamically generated images. That would protect against copy-pasting. You'll have to decide how much of a protection that really is, though - most short questions can be typed into Google in no time, can't they?

Solution 4 - Html

Note that this question might be found via Google by people who want to override a no-copy rule via a Greasemonkey script or the like on the browser side.

In addition to select disabling, I've seen the following tactic in at least one website:

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

Solution 5 - Html

You could also make the page an image instead of html/text.

It is not easy to copy the text from an image. It would have to be saved and OCR'd.

Solution 6 - Html

Could you place a transparent PNG on top of the element that contains the quiz/question?

Solution 7 - Html

If you are using JQuery then use:

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";
}

Call this function where you want to disable.

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

Solution 8 - Html

For future googlers who may not want to block highlighting or want to allow user to copy a limited number of characters :

  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();
  }

Solution 9 - Html

You could query each given answer with google and in case there is no exact match, it's very likely that the user has typed it in by him/herself and you can grant points.

Solution 10 - Html

<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>
  

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAntonView Question on Stackoverflow
Solution 1 - HtmlmowwwalkerView Answer on Stackoverflow
Solution 2 - HtmlAnuj KaithwasView Answer on Stackoverflow
Solution 3 - HtmlPekkaView Answer on Stackoverflow
Solution 4 - HtmlshiggityView Answer on Stackoverflow
Solution 5 - HtmlGuestView Answer on Stackoverflow
Solution 6 - HtmlCornel GhibanView Answer on Stackoverflow
Solution 7 - HtmlSheetal Kumar MauryaView Answer on Stackoverflow
Solution 8 - HtmlIlan SchemoulView Answer on Stackoverflow
Solution 9 - HtmlTorbjörnView Answer on Stackoverflow
Solution 10 - HtmlAlok Goyal Dadri U.PView Answer on Stackoverflow