可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
回答1:
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.
回答2:
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...
回答3:
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?
回答4:
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.
回答5:
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>
回答6:
Could you place a transparent PNG on top of the element that contains the quiz/question?
回答7:
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);
});
回答8:
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.
回答9:
<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>