How to redirect to URL/submit button on time out of page?

209 views
Skip to first unread message

oTree User

unread,
Sep 20, 2021, 9:15:46 AM9/20/21
to oTree help & discussion

In order to prevent that participants take too long for my experiment on the last page, I want them to redirect to a URL (Prolific completion url) on a specified automatic time-out of the page.
I tried it with jQuery and the finish.countdown function. I have this code:

Pages:
timeout_seconds = 35
timer_text = 'Unless you continue, page will auto-submit in:'

Javascript:
<script>
$(function () {
        $('.otree-timer__time-left').on('update.countdown'function (event) {
            if (event.offset.totalSeconds === 20) {
                $('.otree-timer').show();
            }
        });
    });

    $(function () {
        $('.otree-timer__time-left').on('finish.countdown'function () {
            window.open("https://google.com""_blank");
        });
    });
</script>

<style>
    .otree-timer {
        displaynone;
    }
</style>

Somehow, it is not working and I cannot find the problem. It only shows "No more pages left." and does not redirect. What would also work for me would be to make a button be submitted on timeout.

Tobias

unread,
Sep 20, 2021, 12:34:33 PM9/20/21
to oTree help & discussion
You could use a meta tag 

<meta http-equiv="refresh" content="10; URL=https://www.google.com" />

In this example, the participant is redirected to google.com after 10 seconds.

No need for timeouts or jquery


Reply all
Reply to author
Forward
0 new messages