Question
JavaScript Timer, prevent reset when page is refreshed (works - but not on mobile)
Hi All,
From searches in the Community, I know plenty of people are interested in a timer that does not "reset" when the page is refreshed (as the Qualtrics Timer question type does). I have been working on a solution / workaround, and I have found something that works - but I have problems getting it to work on mobile devices.
Brief description of my solution:
* Before each block, set embedded data field "TimeStartedBlock" = Q_TotalDuration
* Then, use JavaScript to pull in "TimeStartedBlock" as well as current Q_TotalDuration
* Use JavaScript to do a few computations to check whether the timer is expired, and click the Next button if that is the case
Here is what it looks like:
```
Qualtrics.SurveyEngine.addOnReady(function()
{
var MaxTime = parseInt("${e://Field/TimePerBlock}"); /// Set this once in Survey Flow
var TimeStart = parseInt("${e://Field/TimeStartedBlock}"); /// Before each block, set this embedded data field to equal Q_TotalDuration
var TimeNow = parseInt("${e://Field/Q_TotalDuration}");
var TimePassed = TimeNow - TimeStart;
var TimeRemaining = MaxTime- TimePassed;
this.clickNextButton.delay(TimeRemaining);
});
```
This works well when I complete the survey on a computer. However, I am having problems getting this to work on mobile devices.
It seems to me that it fails when pulling in Q_TotalDuration for "TimeNow". When I refresh the page (using the refresh button in Safari, or by pulling down on Google Chrome), the TimeNow variable still has the same value as it did the first time the page was loaded.
Thanks for any help you can provide.
Of course, if anyone has a more sophisticated way of addressing the issue of resetting timers, I am open to any and all solutions!
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
