Weather App - Javascript Error Only happens in ie(11) edge and opera. Help please

Weather App - Javascript Error Only happens in ie(11) edge and opera. Help please
0

#1

Hi all,

i’m making my weather app and have pretty much done. I did a little broiwser testing and in the browsers mentioned it doesnt work because of a js error -

: Unable to get property ‘1’ of undefined or null reference, it is refering to line 134 in the js.

Opera gives me nothing in the console, I found the error only in ms browsers.

In Firefox and Chrome the app works really well.

I havn’t been able to figure this one out :frowning2:

Codepen

Cheers

Mark


#3

EDIT:

A compatability test at http://jscc.info/ returned ok too :confused:


#4

There’s a lot going on in this app - what specifically isn’t working?


#5

Something is going wrong when convertTime is called with getTime. For some reason it’s not finding a match with the regex and thus returning null. I hard coded a string for getTime and it works. Using your current implementation of getTime fails.

While writing this I did more testing. There are invisible characters throughout the string made by toLocaleTimeString. See this answer on stackoverflow for more details: http://stackoverflow.com/questions/21413757/tolocaledatestring-changes-in-ie11

If you call .replace(/[^ -~]/g,’’) on getTime, or just put it after the toLocaleTimeString call, it should fix the issue, it worked when I tried it.


#6

Hi, it hangs in IE on a JS error in a time function…


#7

Thanks for that, i will see if i can get it working with that when i get in fron of computer properly.

Cheers


#8

Hi,

The .replace() method did have an effect but it the error just moved a couple of lines down and the app hung again in ie.

I went and read your link again and googled a bit more.

In the comments of your link I found that toLocaleTimeString should only be used for human representations of strings and to use other methods if you intend the time to be used by the machine.

so I changed this:

var getTimeNow = new Date(new Date().getTime()).toLocaleTimeString(‘en-uk’, {
hour: ‘numeric’,
minute: ‘numeric’
});

to this:

var getTimeNow = new Date(new Date().getTime()).toTimeString(‘en-uk’, {
hour: ‘numeric’,
minute: ‘numeric’
});

and hey presto, ie11 then became the fast performing browser of opera, firefox, edge, chrome and ie.

So, thank you sir for putting me on the right track.

Mark

On a side note, maybe for another thread/time:

ie being fast made alarm bells ring because a) ie being fastest should not happen, and b) I kinda hoped the performance trouble I was having was down to this error.

So as a bit of pleniminary diagnosis I just disabled my geo feature & error checking function to skip directly to the fetch function and the performance issues go away… good job i’m enjoying these issues eh?

EDIT:

I also fixed the performance issue. I was calling geolocate again when i didnt have too. Its been a fine morning of novice bug squashing! :smiley: