PP Remote Testing Wiki | Examples / ExampleCognitionWorkaround
Examples / ExampleCognitionWorkaroundOther example reports ( tutorials / technical issues / workarounds ) Workaround for Cognition.run Development LimitationsLimitations
Why does this matter?The limitations above make it difficult for a project containing multiple JavaScript modules to be hosted on Cognition. WorkaroundUsing the following code copied from this stackoverflow answer (under "Dynamic Script Loading") you can dynamically create a script element that loads a JavaScript module. // https://stackoverflow.com/a/950146 function loadScript(url, callback) { // Adding the script tag to the head as suggested before var head = document.head; var script = document.createElement('script'); script.type = 'module'; script.src = url; // Then bind the event to the callback function. // There are several events for cross browser compatibility. script.onreadystatechange = callback; script.onload = callback; // Fire the loading head.appendChild(script); } To use this technique in a Cognition task simply copy the function listed above to the editor and invoke it passing the URL of your source file. loadScript( "https://cdn.jsdelivr.net/gh/BoysTownorg/simon-game-js@2.4.0/jspsych/main/colored-circles.js", function () {} ); If your JavaScript files are on GitHub you can use jsDelivr to load your files (see this answer). In order to load jsPsych the primary script must mention the plugins used. This can be achieved by simply inserting comments in the editor such as the following.
|
Edit – History – Print – Recent Changes – Search
Page last modified on August 31, 2020, at 05:38 PM