IE在UserAgent中报告两个版本是什么意思? [英] What does it mean when IE reports two versions in UserAgent?

查看:175
本文介绍了IE在UserAgent中报告两个版本是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到IE使用者字符串有多个部分报告为不同版本的情况。例如:

I'm seeing cases where the IE useragent string has multiple parts reporting to be different versions. For example:

   Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; 
   {B93AEBFF-7B72-44EA-B006-8CB078CC1911}; 
   Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; 
   .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; 
   .NET CLR 3.5.30729)

所以这是声称是MSIE 8.0,也是MSIE 6.0。这是否意味着什么特别的?它是IE的股票还是有什么特别之处?

So this is claiming to be MSIE 8.0, but also MSIE 6.0 . Does this mean anything special? Is it a stock IE or is there something special about it?

我问,因为我看到报告多个版本而不是另一个IE8的浏览器的奇怪行为。 0声称单个版本:

I ask because I'm seeing strange behavior with the browser that reports multiple versions but not with another IE8.0 that claims a single version:

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; 
Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; 
.NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)

不确定使用者是否与此有任何关系,但我想我会问。

Not sure if the useragent has anything to do with it, but I thought I'd ask.

[更新]请注意,我不是针对特定的浏览器版本进行编码,我只是注意到这是一个奇怪的浏览器和那些没有的浏览器之间的区别。我想知道是什么会导致一些IE8.0报告他们也是IE6.0其他人没有。

[Update] Note that I'm not coding against particular browser versions, I just noticed this as a difference between the browser that was behaving strangely and the ones that were not. I wanted to know what would cause some IE8.0's to report they're also IE6.0 others not.

推荐答案

Lou的回答是正确的但我会扩展它。

Lou's answer is correct but I'll expand on it.

用户代理字符串可用于网页上运行的JavaScript代码。不幸的是,在Web开发人员中检查用户代理字符串以执行特定于浏览器的增强或解决方法是相当普遍(和不好)的做法。

User agent strings is available to JavaScript code running on a web page. Unfortunately it's rather common (and bad) practice among web developers to check user agent string to perform browser-specific enhancements or workarounds.

当具有升级功能的新浏览器出现时介绍说,他们的开发人员意识到许多网站不能在其中工作或以降级的方式工作,因为用户代理检查不正确并且在代码中采用了错误的路径。这导致浏览器开发人员修改其用户代理字符串,以便采用正确的路径。这导致了当前的情况,每个浏览器都假装是Mozilla,而且一般来说用户代理字符串都非常混乱。

When new browsers, with upgraded capabilities, were introduced, their developers realized that many web sites didn't work in them or worked in a degraded way, because user agent checks were done incorrectly and taking wrong paths in the code. This led browser developers to modify their user agent strings so that a correct path is taken. This led to current situation, where every browser pretends to be Mozilla and in general user agent strings are quite a mess.

因此,您看到的网站很可能行为不端正在执行用户代理检查而不是正确执行。正如Lou所说,JavaScript代码不应该尝试解析用户代理(这是一种非常脆弱的方式来测试浏览器,很可能会破坏未来版本的浏览器),而是检查浏览器功能。当前流行的JavaScript库(如jQuery)以正确的方式执行(使用它们的另一个原因)但仍然会发生自定义编写的JavaScript代码将尝试使用用户代理字符串。

It's therefore quite possible that a website that you see misbehaving is performing user agent check and not doing it right. As Lou said, JavaScript code shouldn't try to parse user agent (which is a very fragile way to test for a browser and very likely to break with future versions of the browser) but instead check for browser capabilities. Current popular JavaScript library (like jQuery) do it the right way (one more reason to use them) but it still happens that custom written JavaScript code will try to use user agent string.

这篇关于IE在UserAgent中报告两个版本是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆