Passing a variable from study to study in JATOS via URL
in JATOS
Dear All,
Where can I find the value of a variable in JATOS if I transfer it from the first study to the second study via URL (for example, with the command window.location.href = "https://jatos.mindprobe.eu/publix/tT100ELC7xs?id= " + 77777;) and how can I write it in the results in another study?
Thanks for reply,
Marko
Comments
Hi @marko ,
If the experiment is hosted on a JATOS server, URL parameters are available in
jaros.urlQueryParameters. If the experiment is running as a standalone HTML file (e.g. during testing), the parameter is available through theURLSearchParamsclass.The example below shows how you can get the
taskURL parameter in a way that works both when running the experiment through JATOS and when running it standalone. (The script assumes thattaskis a number.)// Check if the task was passed a url parameter through JATOS if ((typeof jatos !== 'undefined') && ('task' in jatos.urlQueryParameters)) { task = Number(jatos.urlQueryParameters['task']) console.log(`task ${task} was specified as a JATOS URL query`) // Else check if it was passed as a regular parameter (for testing) // and fall back to 0 if no parameter was specified. } else { const urlParams = new URLSearchParams(window.location.search) task = Number(urlParams.get('task') || 0) if (task === 0) { console.log('no task was specified') } else { console.log(`task ${task} was specified as a regular URL query`) } }Hope this helps!
— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
I agree with Sebastian and just want to answer your second question: how to write it in the results of the second study: Use on of the functions
jatos.submitResultDataorjatos.appendResultData.Best,
Kristian
Dear Sebastian and Kristian,
Thank you for the answer. Now I see that I have another related question: How can I insert the value of some variable from the first experiment into the URL. So, if in the first experiment I generate the value of the variable "idisp", how can I transfer the value of that variable through the URL to the next experiment. Experiments are linked in JATOS via the "End Redirect URL" option.
Thank you again,
Marko
Hi Marko,
Somehow your second question got lost. It's better to start a new question in the forum so this doesn't happen and also so other people can find it easier.
You would use
jatos.endStudyAndRedirectto end your study, redirect it to a different page and pass on information via the URL query parameters. The "End Redirect URL" option in the study properties does the same but I guess you want to pass a parameter that only exists in your code.Here is an example
myParameter=1234ABCDyou'd have the URLhttps://www.example.com/base/publix/Hbr4mxMnyjt?myParameter=1234ABCD.jatos.endStudyAndRedirectin your first study to redirect to your second study:jatos.endStudyAndRedirect("https://www.example.com/publix/Hbr4mxMnyjt?myParameter=1234ABCD");You can pass on as many parameters as you want, just separate them by '&'.
Best,
Kristian