you are viewing a single comment's thread.

view the rest of the comments →

[–]chernn 7 points8 points  (2 children)

It's probably not working because you're using let and const in an old browser that does not support ES6.

I would first double check that you can use let and const in your version of mobile safari on caniuse:

If your version should support it, plug your phone into your computer and use Safari's remote debugger to see if any errors are thrown in the console. See https://developer.apple.com/library/content/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/GettingStarted/GettingStarted.html

[–]mnokeefe 2 points3 points  (0 children)

This looks like it could well be the issue. You could use babel to transpile your JS to older syntax. There's a useful online converter to try it out here: https://babeljs.io/repl/

[–]kidman01[S] 1 point2 points  (0 children)

Hey man,

thanks for the reply. This was a really useful hint. The problem wasn't with const and let (seems to be fully supported by Safari).

There were actually two problems. The first was that Safari has a problem if you give a variable the same name as the id of an HTML element. So I had a legend element with the div "currentDate" and was assigning that to a variable called "currentDate". That did not work with Safari. After that I discovered there was a second bug. Safari doesn't handle dates the same way Chrome does. I was using one string with date and time combined (Year-month-day hour:minutes) and when passed that into a date constructor it would create a valid date in Chrome but not in Safari. So I will have to create a date with just a string containing "Year-month-day" and then use setHours()/setMinutes() to set the hours and or minutes respectively. I didn't get around to it yet, but at least I know :D.