Prevent copying text in web-page

2019-01-21 10:46发布

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

9条回答
Animai°情兽
2楼-- · 2019-01-21 11:22

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);
});
查看更多
Rolldiameter
3楼-- · 2019-01-21 11:24

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.

查看更多
We Are One
4楼-- · 2019-01-21 11:25

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.

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-01-21 11:27

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

查看更多
神经病院院长
6楼-- · 2019-01-21 11:28

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

查看更多
甜甜的少女心
7楼-- · 2019-01-21 11:31
<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>
查看更多
登录 后发表回答