最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does IE 8 navigator.userAgent return MSIE 7.0? - Stack Overflow

programmeradmin2浏览0评论

I am trying to implement a browser support feature on my webpage. For Firefox 3.6 it is working fine, but for some reason IE 8's userAgent is returning a wrong value.

Here is the scenario, when I run a 'local' javascript code on IE8, navigator.userAgent returns correct information (MSIE 8.0). But when I run this script on a server, it returns MSIE 7.0 on an IE 8 browser.

Any ideas?

I am trying to implement a browser support feature on my webpage. For Firefox 3.6 it is working fine, but for some reason IE 8's userAgent is returning a wrong value.

Here is the scenario, when I run a 'local' javascript code on IE8, navigator.userAgent returns correct information (MSIE 8.0). But when I run this script on a server, it returns MSIE 7.0 on an IE 8 browser.

Any ideas?

Share Improve this question asked Oct 14, 2011 at 23:42 SunSun 5802 gold badges9 silver badges31 bronze badges 3
  • 2 if you are sniffing user agents, you're doing it wrong and you're going to have a bunch of problems like that. you should use feature detection, but you could also just set up conditional ments for ie7 and ie8 and change some css to see what is going on. – albert Commented Oct 14, 2011 at 23:48
  • 1 Using feature detection as opposed to browser sniffing would be more robust, there are plenty of libraries out there, try this Google search – Clive Commented Oct 14, 2011 at 23:49
  • 1 Is the server on your local network or on the internet? IE8, by default, pretends to be IE7 when browsing intranet sites. – robertc Commented Oct 15, 2011 at 0:28
Add a ment  | 

3 Answers 3

Reset to default 6

You need to check Trident token too.

Trident token

When the F12 developer tools are used to change the browser mode of Internet Explorer, the version token of the user-agent string is modified to appear so that the browser appears to be an earlier version. This is done to allow browser specific content to be served to Internet Explorer and is usually necessary only when websites have not been updated to reflect current versions of the browser.

When this happens, a Trident token is added to the user-agent string. This token includes a version number that enables you to identify the version of the browser, regardless of the current browser mode.

MORE : http://msdn.microsoft./en-us/library/ms537503.aspx

Are you sure you aren't running in IE7 mode? You can change it somewhere in the Developer settings (F12, I think).

Microsoft provides this page:

http://msdn.microsoft./en-us/library/ms537509(v=vs.85).aspx

According to the Javascript sample one would think IE8 would return an 8, not a 7.

发布评论

评论列表(0)

  1. 暂无评论