Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
Javascript patch to grab MTurker ID

I am trying to use the snippet of code below to embed MTurkers' worker IDs as part of a URL. When they click the redirect URL, it sends them to a task, and if I can attach their worker ID to the URL my task will grab that embedded data so I can identify them later. However, the code is not grabbing their ID. Someone offered a modification to the code that should fix it, but I can't figure out where to put the new code.

This is the original code:

<div id="myelementLink" style="display: inline; font-family: Verdana;"><tt>URL not shown because there is an error with Javascript on your computer. To perform this HIT, you must have Javascript and cookies enabled on your browser.</tt></div>
<script type="text/javascript" language="JavaScript"><!--
var assignment_id_field = document.getElementById('myelementLink');
var paramstr = window.location.search.substring(1);
var parampairs = paramstr.split("&");
var mturkworkerID = "";
for (i in parampairs) {
  var pair = parampairs[i].split("=");
  if (pair[0] == "workerId")
    mturkworkerID = pair[1];
}
if (mturkworkerID == "" ) {
  assignment_id_field.innerHTML = '<tt>The link will appear here only if you accept this HIT.</tt>';
} else {
  assignment_id_field.innerHTML = '<a target="_blank" href="https://YOUR_QUALTRICS_SURVEY_URL_GOES_HERE&MID=' + mturkworkerID + '"><h1><span style="color: rgb(255, 0, 0);"><span style="font-family: Courier New;"><b>CLICK HERE TO TAKE THE SURVEY!</b></span></span></h1></a>';
}

// --></script>

<div class="link" id="linkDiv">&nbsp;</div>

This is the part I'm supposed to add to fix it:

var current_url = new URL(window.location.href);
var workerID = current_url.searchParams.get("workerId");
console.log("The worker ID is: " + workerID);

Where should I put it?

(PS link to the post where I got the code.)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!