58

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

Anton
  • 5,831
  • 3
  • 35
  • 45
  • 4
    How are you planning to stop people with a functioning memory from typing stuff into search engines? – David Thomas Jan 21 '12 at 22:59
  • Typing require much more time. While typing, next question will be asked – Anton Jan 21 '12 at 23:01
  • make screen full screen, and if it goes out of focus or exit fullscreen detect that and cancel the test forever. – Muhammad Umer Aug 10 '13 at 10:44
  • have 20 versions of the same question reworded. – Muhammad Umer Aug 10 '13 at 10:45
  • generate random id, disable left/right click, selection, restrict time, make questions loooong and a picture. But in the end people can still talk about it.lol. – Muhammad Umer Aug 10 '13 at 10:47
  • 3
    If user is Tech savvy then he can copy still using firebug / developer tools from FIrefox/chrome. so using image is best option for you. – Kishan Gajjar Jan 02 '14 at 07:18
  • Possible duplicate of [How to disable text selection highlighting using CSS?](https://stackoverflow.com/questions/826782/how-to-disable-text-selection-highlighting-using-css) – Teja Bhagavan Kollepara May 29 '17 at 06:42
  • Disabling context menus is futile. See my suggestion below for a solution that does work. – WilliamK Aug 17 '21 at 14:36
  • Related question, [javascript - How to add extra info to copied web text - Stack Overflow](https://stackoverflow.com/questions/2026335/how-to-add-extra-info-to-copied-web-text) – user202729 Jul 17 '22 at 16:55

11 Answers11

125

Here: How to disable text selection highlighting using CSS?

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

Community
  • 1
  • 1
mowwwalker
  • 16,634
  • 25
  • 104
  • 157
  • This is also good for putting on container div's where you may display a map from Google Maps, MapQuest, etc. – Micky McQuade Oct 23 '13 at 19:46
  • Awesome. I used this with a [foggy plugin](http://nbartlomiej.github.io/foggy/) to hide content before subscription. – JacobLett Feb 11 '16 at 17:14
28

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

Anuj Kaithwas
  • 803
  • 1
  • 10
  • 30
17

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?

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
9

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>
shiggity
  • 531
  • 4
  • 12
5

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.

Paulo Tomé
  • 1,910
  • 3
  • 18
  • 27
Guest
  • 51
  • 1
  • 1
4

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

Cornel Ghiban
  • 902
  • 4
  • 6
3

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

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();
  }
Ilan Schemoul
  • 1,461
  • 12
  • 17
0
<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>
Shikkediel
  • 5,195
  • 16
  • 45
  • 77
0

For normal users, you can simply set the "draggable=true" on body, div or any other element and will look like an image to avoid its copying. Offcourse JS option is there. Both are applied in Here

0

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.

Torbjörn
  • 5,512
  • 7
  • 46
  • 73