newhtml doesn’t work

PennController for IBEX Forums Support newhtml doesn’t work

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #10450
    hailinguist
    Participant

    I 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!

    #10451
    Jeremy
    Keymaster

    Hello,

    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

    #10452
    hailinguist
    Participant

    Hi 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/

    #10453
    hailinguist
    Participant

    Hi 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>
    #10454
    Jeremy
    Keymaster

    Hi,

    You can still use items = [ ["completion", "Form", {continueMessage: null, html: { include: "completion.html" }}] ] if you’d like

    When inserted inside a PennController trial via newHtml, the DOM elements are not added immediately, so document.getElementById("demo") will be undefined 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

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.