-
Notifications
You must be signed in to change notification settings - Fork 18
Soft Block Javascript
Sometimes it is helpful to prevent workers from seeing particular contents of a HIT until after they accept it (e.g., a link to an off-site survey) as well as preventing workers from completing a HIT if you have (for whatever reason) deemed them ineligible. Qualifications (possibly with a Qualification Test) are the best ways to handle this. But, you can also "soft block" workers using javascript. This way, if they accept the HIT, they are prevented from completing it.
Note that this can backfire because workers have to return the HIT, which negatively affects one of their worker statistics. A better strategy is always to use qualifications. But, if your HIT properly describes that this "soft block" is in place and provides a way for workers to check whether they are eligible, this mechanism is relatively easy to setup and relatively painless from a worker perspective.
Here's some example code:
<script type="text/javascript">
// DEFINE FUNCTION TO EXTRACT PARAMETERS FROM URL
function turkGetParam( name ) {
var regexS = "[\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var tmpURL = fullurl;
var results = regex.exec( tmpURL );
if( results == null ) {
return "";
} else {
return results[1];
}
}
// THIS IS THE LINE TO CAPTURE THE ACTUAL URL:
var fullurl = window.location.href;
// ASSIGNS THE URL PARAMETERS TO JAVASCRIPT VARIABLES
var assign = turkGetParam('assignmentId');
var hit = turkGetParam('hitId');
var worker = turkGetParam('workerId');
// WHAT TO DO IF THE WORKER IS PREVIEWING THE HIT
if(assign=="ASSIGNMENT_ID_NOT_AVAILABLE")
{
document.write("<p style='font-weight:bold;text-align:center;'>Link will become available once you accept the HIT.</p>");
}
// CHECK workerId AGAINST THE LIST OF INELIGIBLE WORKERS
else if (worker=="A23JA6ICO4BPQ5" ||
worker=="A3DTS2LSSZGK5W" ||
worker=="A3JMPI8HZATQ4Q" ||
worker=="AFIIFNK4FM7MZ"
)
{
// DISPLAY AN ERROR MESSAGE TO THE WORKER
document.write("<b>You have already completed this survey and are therefore ineligible to complete it again. Sorry.</b>");
}
// IF NOT IN THE ABOVE LIST AND NOT PREVIEWING, DISPLAY LINK
// COULD BE RECONFIGURED TO DO SOMETHING ELSE, BUT THIS IS A SIMPLE EXAMPLE
else {
// CREATE A HYPERLINK URL TO BE DISPLAYED
var surveylink = new String("http://www.example.com/" + "?assignmentId=" + assign + "&hitId=" + hit + "&workerId=" + worker);
// DISPLAY THE LINK
document.write("<a href=\"" + surveylink + "\" target=\"_blank\">Click here to complete the survey</a><br />");
}
</script>
.