Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE9.js Cannot read property '1' of null / navigator.appVersion.match(...) is null Line 6 [closed]

Tags:

javascript

I've included Google's IE7/IE8/IE9.js to my website, now I get the following error in Chrome: Uncaught TypeError: Cannot read property '1' of null IE9.js:6

Firefox is a bit more detailed: navigator.appVersion.match(...) is null Line 6

What did I do wrong?

like image 993
estrar Avatar asked Dec 02 '25 10:12

estrar


1 Answers

The code in question reads:

var q=h.appVersion=navigator.appVersion.match(/MSIE (\d\.\d)/)[1]-0

Since neither Chrome nor Firefox have "MSIE" in their appVersion, the method returns null, and then the code tries to get the property called 1 from null. Hence the exception.

You could include the script using conditional comments to prevent this error.

<!--[if IE]>
<script src="IE9.js" type="text/javascript"></script>
<![endif]-->
like image 52
Matt Ellen Avatar answered Dec 04 '25 23:12

Matt Ellen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!