0

I'm having the weirdest problem. I have a web app hosted on an IIS server that won't work in IE8, which is the standard browser at this company. It works in chrome. I've also put identical files hosted on my google drive, and it works there, even in IE8. It also works when the files are just on my desktop, even in IE8.

It turns out that the problem is specifically caused by the fact that when the app is hosted on that server, javascript in IE8 won't parse strings. Here is some example code:

<!doctype html>
<html>
<body>
<script type="text/javascript">
var test='test';
console.log(test[2]);
</script></body>
</html>

That's it. The entire document. When I host this on the IIS server and open IE8's console, instead of logging s like it should, I get

LOG: undefined

In chrome, I get s When I host the file anywhere else, I get s even in IE8. But when it's viewed in IE8 and hosted on this server, I get undefined. What's going on here?

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Matthew
  • 4,149
  • 2
  • 26
  • 53
  • are you sure you're running in the same document mode in IE8 in both environments? it was either IE7 or IE8 that couldn't reference a string using that syntax. – Kevin B Oct 09 '14 at 14:23

2 Answers2

1

Turns out it was a compatibility view issue. Code works with compatibility view is off. Since all our computers view intranet sites in compatibility view I added <meta http-equiv="X-UA-Compatible" content="IE=8" /> to the html head to prevent compatibility view. The app works now.

Matthew
  • 4,149
  • 2
  • 26
  • 53
0

IE8 may not support a string as an array of chars. See this question How do you get a string to a character array in JavaScript?

It may even be down to your server changing the compatibility mode of the browser.

Instead do

window.console&&console.log(test.charAt(2));

I am adding the window.console&& to not get an error in IE8 when the console is not open

Community
  • 1
  • 1
mplungjan
  • 169,008
  • 28
  • 173
  • 236