Custom javascript only works with browsers on laptops but not on mobile devices? | XM Community
Skip to main content
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!
@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.
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!
> @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> ```