Custom javascript only works with browsers on laptops but not on mobile devices? | XM Community
Skip to main content
Solved

Custom javascript only works with browsers on laptops but not on mobile devices?

  • March 3, 2019
  • 3 replies
  • 116 views

Hello community, I included a custom javascript in my survey to get the local date and time when my respondents load the survey page. The logic flow I set in the survey then used these variables in the javascript as embedded data to decide which page to display. The codes work like a charm only with Chrome on my mac. _However, it didn't work on safari on mac nor safari/chrome on my iPhone/iPad._ Below is the script I included in my survey: var d = new Date(); Qualtrics.SurveyEngine.setEmbeddedData("hour", d.getHours()); var start = new Date(2019-3-3), end = new Date(), diff = new Date(end - start), days = Math.floor (diff/1000/60/60/24); Qualtrics.SurveyEngine.setEmbeddedData('day',days); Any thoughts why such an issue, and how I can make it to work across browsers and devices? Thanks!

Best answer by TomG

> @echongsk said: > Thanks for your reply, @TomG! How do you install moment.js in qualtrics? I'm not experienced with this. Any suggestions would be helpful. Thank you! Add this to your header: ``` <script src="https://cdn.jsdelivr.net/npm/moment@2/moment.min.js"></script> ```

3 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • March 3, 2019
@echongsk, My guess is that Safari isn't parsing 2019-3-3 correctly. Date parsing is inconsistent among browsers. I recommend using moment.js moment.js for anything beyond basic date handling such as parsing, arithmetic and formatting.

  • Author
  • March 3, 2019
Thanks for your reply, @TomG! How do you install moment.js in qualtrics? I'm not experienced with this. Any suggestions would be helpful. Thank you!

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • March 3, 2019
> @echongsk said: > Thanks for your reply, @TomG! How do you install moment.js in qualtrics? I'm not experienced with this. Any suggestions would be helpful. Thank you! Add this to your header: ``` <script src="https://cdn.jsdelivr.net/npm/moment@2/moment.min.js"></script> ```