Anton
Anton

Reputation: 6061

Prevent copying text in web-page

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

Upvotes: 68

Views: 161023

Answers (11)

Mukhtiar Zamin
Mukhtiar Zamin

Reputation: 63

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

Upvotes: 1

Ilan Schemoul
Ilan Schemoul

Reputation: 1662

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

Upvotes: 2

Sheetal Kumar Maurya
Sheetal Kumar Maurya

Reputation: 174

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

Upvotes: 3

Alok Goyal Dadri U.P
Alok Goyal Dadri U.P

Reputation: 21

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

Upvotes: 0

shiggity
shiggity

Reputation: 561

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>

Upvotes: 11

Anuj Kaithwas
Anuj Kaithwas

Reputation: 842

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

Upvotes: 30

Guest
Guest

Reputation: 51

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.

Upvotes: 5

Cornel Ghiban
Cornel Ghiban

Reputation: 902

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

Upvotes: 4

Torbj&#246;rn
Torbj&#246;rn

Reputation: 5820

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.

Upvotes: 0

mowwwalker
mowwwalker

Reputation: 17392

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.

Upvotes: 138

Pekka
Pekka

Reputation: 449783

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?

Upvotes: 19

Related Questions