views:

82

answers:

7

I have written a web app that requires IE version 8 (or higher presumably). If I run IE8 on a clean windows install on a VM it reports 'MSIE 8.0' as a user agent when queried with navigator.userAgent in javascript. But on a colleagues windows 7 machine his IE reports version 8 in the Help|About window, but the user agent string is 'MSIE 7.0'.

I figure that somewhere on his machine there is a setting that's telling IE to spoof the previous version, some kind of compatibility setting I presume, but for the life of me I can't find it. I'm not setting up quirksmode or IE7 compatibility mode from my end.

+5  A: 

The user agent is not a sensible or reliable way of determining the browser version. Why don't you look for the presence of the feature you require by making it IE8 only and use that? That is a much more reliable method.

Woody
A: 

http://www.modernizr.com/

It should detect such issues. Alternatively, I'm not sure but IE 8 might switch its User-Agent tag in 'Compatibility Mode'.

Rushyo
UA sniffing is even worse than version detection in JS - see Chrome's UA for a taste of the insanity: `User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.9 Safari/533.2` (some braindead scripts are looking for "Gecko" in the script, because that's what Firefox has; and don't get me started on the initial "Mozilla")
Piskvor
@Rushyo Modernizr detects *features*, not bugs, incompatibility or browser versions
Yi Jiang
@Yi Jiang: ah ok, I must have misunderstood. I was reacting to the part about User-agent.
Piskvor
@Piskvor And I was responding to the original poster of this answer... Your comment didn't showed up when I was typing the comment.... clarified.
Yi Jiang
@Yi Jiang: Which is often (usually?) the legitimate intent of people asking questions about user agent sniffing.@Piskvor: I wasn't advocating anything, just responding to the question. He wanted to see what was weird with his scenario - I suspect it might have been that.
Rushyo
A: 

Could you use conditional comments?

<script>
  var is_ie8 = false;
</script>
<!--[if IE 8]>
  <script>
    is_ie8 = true;
  </script>
<![endif]-->
Piskvor
+1  A: 
<meta http-equiv="X-UA-Compatible" content="IE=8">
<script type="text/javascript">
var is_ie8_or_better = false;
</script>
<!--[if gte IE 8]>
<script type="text/javascript">
is_ie8_or_better = true;
</script>
<![endif]-->
David Dorward
Won't detect Opera-spoofing unfortunately...
Rushyo
i'm not sure if that works for a browser running in compatibility mode. have you tested it?
geowa4
@Rushyo: I think that's just what you want: Opera presenting itself as IE is still Opera and acts like Opera.
Marcel Korpel
Depends. To override a user's intent is typically a bad thing(tm). Then again, the user is an idiot for relying on spoofing.
Rushyo
@Rushyo: But Opera only put spoofing in Opera to let users use sites that rely on (bad) browser sniffing, so they can use sites that otherwise would be inaccessible (that's also why this is a per-site setting).
Marcel Korpel
A: 
Pointy
That's very much like http://gist.github.com/527683, http://gist.github.com/542301 and http://gist.github.com/548648
Marcel Korpel
yes I didn't make it up; I'm not smart enough for that :-)
Pointy
A: 

The only way I can figure out how to get my version of IE8 to say that it is IE7 is to enable Compatibility View. See http://blogs.msdn.com/b/ie/archive/2008/08/27/introducing-compatibility-view.aspx

geowa4
A: 

Turns out his browser was set to display all 'intranet sites' in compatibility mode. Also, yes, compatibility mode changes the user agent string.