Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript not working on Safari (Mac and iOS)

I've implemented an instant search function using javascript on my jekyll site: https://cecilialee.github.io (Repository: https://github.com/cecilialee/cecilialee.github.io)

It works perfectly on Chrome and Firefox. However, when I test it on Safari, no matter on Mac or iPhone, the script doesn't seem working..

What can I do?

like image 623
Cecilia Lee Avatar asked Jan 04 '23 03:01

Cecilia Lee


1 Answers

Ok I found the answer.

When I inspect on Safari, I found SyntaxError: Can't create duplicate variable that shadows a global property: 'results'.

This is apparently a problem Safari has with declaring a let/const variable that shares the same name as a selected id attribute. I had some variables declared with const as you did and got the same error. Changed to let and still got it. Changed to var and it worked.

Reference: "can't create duplicate variable that shadows a global property"

Hence, I changed some of my JavaScript const to avoid duplication with id. And the script works like a charm again!

like image 164
Cecilia Lee Avatar answered Jan 13 '23 18:01

Cecilia Lee