PennController for IBEX › Forums › Support › newhtml doesn’t work
- This topic has 4 replies, 2 voices, and was last updated 1 year, 9 months ago by
Jeremy.
-
AuthorPosts
-
April 14, 2023 at 2:39 am #10450
hailinguist
ParticipantI tried to link my completion page with a HTML file but it doesn’t work. The code I used is below. I also have the HTML file under my resources tab.
newHtml("final", "completion.html") .print()
This is how I defined my sequence:
Sequence("infosheet","getID","age_check","biographics","instructions","practice-trial","beginExp", randomize("experimental-trial"), SendResults(),"final")
So, basically, the final page does not show up at all (neither on the experiment nor in the sequence). May I what went wrong here? Thanks!
April 14, 2023 at 7:07 am #10451Jeremy
KeymasterHello,
Do you call
wait
on any element in your trial labeled “final” so as to halt the execution of the script, and prevent it from finishing the trial immediately?Jeremy
April 14, 2023 at 2:02 pm #10452hailinguist
ParticipantHi Jeremy,
Thanks for your reply.
I don’t have any other elements labeled “final”. A link to the exp is here if it helps: https://farm.pcibex.net/r/PzVNVH/
April 15, 2023 at 6:30 pm #10453hailinguist
ParticipantHi Jeremy,
I changed my code to the following, and the final page shows up:
newTrial("completion", newHtml("completion", "completion.html") .print() .wait() )
However, the function I created in the HTML file for generating a code does not work (i.e., the code simply doesn’t show up). The same HTML file works as intended in the old Ibex: [“completion”, “Form”, {continueMessage: null, html: { include: “completion.html” } } ].
Below is the content of the HTML file. May I know what caused the problem? Thank you so much!
<!DOCTYPE html> <html> <body> <p>恭喜您已经完成了该实验。感谢您的参与。</p> <p>为了获取报酬,请您复制下面的11位数编码,然后点击下面链接或者扫码打开腾讯问卷,在问卷里填写该编码。</p> <p>每个编码只能使用一次。请不要和别人分享。</p> <h3 id="demo"></h3> <p>腾讯问卷链接</p> <img src="qrcode.png" width="300" /> <script> function functionName() { let alphanum = "0123456789"; let code2 = ""; let randChar; while (true) { for (i = 0; i < 10; i++) { randChar = alphanum.charAt(Math.floor(Math.random()*alphanum.length)); code2 += randChar; } if (code2.length > 10) { code2 = ""; } if (code2 % 11 === 1) { break; } } return code2; } document.getElementById("demo").innerHTML = functionName(); </script> </body> </html>
April 17, 2023 at 3:55 am #10454Jeremy
KeymasterHi,
You can still use
items = [ ["completion", "Form", {continueMessage: null, html: { include: "completion.html" }}] ]
if you’d likeWhen inserted inside a PennController trial via newHtml, the DOM elements are not added immediately, so
document.getElementById("demo")
will beundefined
by the time the script gets executed. You could delay execution until the reference is defined:(function ud(){try{document.getElementById("demo").innerHTML = functionName();}catch(e){window.requestAnimationFrame(ud)}})();
Jeremy
-
AuthorPosts
- You must be logged in to reply to this topic.