javascript 使用谷歌浏览器的奇怪用户代理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4024230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Strange User Agent With Google Chrome
提问by Shiv Deepak
I was working with some javascript and found a strange user agent with my Google Chrome.
我正在使用一些 javascript,并在我的 Google Chrome 中发现了一个奇怪的用户代理。
I have Google Chrome 7.0.517.41 beta installed on my Ubuntu Laptop. Now AFAIK my user agent should be something close to Chrome/7.0.517.41
我的 Ubuntu 笔记本电脑上安装了 Google Chrome 7.0.517.41 beta。现在 AFAIK 我的用户代理应该接近 Chrome/7.0.517.41
but it is showing me:
但它向我展示:
Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7
Why is this happening.. I have disabled all the installed extensions but it is still the same..
为什么会发生这种情况..我已经禁用了所有已安装的扩展,但它仍然是一样的..
回答by Piskvor left the building
The UA string tells the long and tragic history of (in)compatibility attempts. See e.g. this for a brief history of the UA. It should also make clear that UA sniffing is useless, as every modern browser pretends to be many other browsers. That is also the case you see here:
UA 字符串讲述了(不)兼容性尝试的漫长而悲惨的历史。参见例如this 了解UA 的简史。还应该清楚 UA 嗅探是无用的,因为每个现代浏览器都伪装成许多其他浏览器。这也是你在这里看到的情况:
- Mozilla - the most ancient artefact, dating from the early 1990s
- X11 - the graphical interface used
- Linux i686 - OS and processor type
- en_US - your locale (English, United States)
- AppleWebKit/534.7 - the actual rendering engine
- (KHTML, like Gecko) - another artifact of browser sniffing: "Gecko" is the FF rendering engine, KHTML is an old rendering engine, predecessor of WebKit (was used by Konqueror browser, than forked by Apple to form WebKit)
- Chrome/7.0.517.41 - the actual browser version
- Safari/537 - yet another artifact against scripts sniffing for "Safari" (which uses the same engine)
- Mozilla - 最古老的人工制品,可追溯到 1990 年代初期
- X11 - 使用的图形界面
- Linux i686 - 操作系统和处理器类型
- en_US - 您的语言环境(英语,美国)
- AppleWebKit/534.7 - 实际的渲染引擎
- (KHTML, like Gecko) - 浏览器嗅探的另一个神器:“Gecko”是FF渲染引擎,KHTML是一个老的渲染引擎,WebKit的前身(被Konqueror浏览器使用,而不是被Apple fork形成WebKit)
- Chrome/7.0.517.41 - 实际浏览器版本
- Safari/537 - 另一个针对脚本嗅探“Safari”(使用相同引擎)的工件
In short: some broken sites assumed that "only allowing people with Mozilla/Firefox/Webkit/whatever" is a sensible policy; in turn, browsers started lying about their origins to get around these artificial barriers. The UA strings are the result: bloatware, full of useless garbage.
简而言之:一些损坏的网站认为“只允许使用 Mozilla/Firefox/Webkit/whatever 的人”是一个明智的政策;反过来,浏览器开始对它们的起源撒谎以绕过这些人为的障碍。结果是 UA 字符串:膨胀软件,充满无用的垃圾。
回答by ajm
Basically, Mozilla stands for "Mozilla compatible" while "KHTML, like Gecko" describes the rendering engine.
基本上,Mozilla 代表“Mozilla 兼容”,而“KHTML,如 Gecko”则描述了渲染引擎。
Essentially, Chrome's user agent string is saying "I'm compatible with Mozilla and my rendering engine is like Gecko" as a way of describing itself to developers.
本质上,Chrome 的用户代理字符串是在说“我与 Mozilla 兼容,我的渲染引擎就像 Gecko”,作为向开发人员描述自己的一种方式。
Most (if not every) browser will identify itself as Mozilla-compatible as a kind of legacy thing, regardless of affiliation with the Mozilla foundation. Yes, even Internet Explorer.
大多数(如果不是每个)浏览器都会将自己标识为与 Mozilla 兼容的一种遗留事物,而不管与 Mozilla 基金会的隶属关系如何。是的,即使是 Internet Explorer。
More info on strings in general at: Mozilla's developer center.
有关字符串的更多信息,请访问:Mozilla 的开发人员中心。
Also, if you're developing based on user agent strings, don't. You'll only find yourself in a world of hurt: browsers get upgraded to implement features and your user agent sniff might still exclude them, user agent strings can be spoofed, and good old Opera likes to report itself as Internet Explorer in older versions.
此外,如果您基于用户代理字符串进行开发,请不要这样做。您只会发现自己处于一个受伤害的世界:浏览器升级以实现功能,您的用户代理嗅探可能仍会排除它们,用户代理字符串可能会被欺骗,而好的老 Opera 喜欢在旧版本中将自己报告为 Internet Explorer。
Instead, use feature detectionto determine if a feature you're trying to use exists for a given browser and then use it or don't.
相反,使用功能检测来确定给定浏览器是否存在您尝试使用的功能,然后使用或不使用它。
回答by gblazex
There are historical reasons for browsers "lying" about themselfs. The main reason for this was user agent sniffing. Opera is the only browser which identifies itself as Opera, all other browsers use Mozilla/5.0 or the older ones Mozilla/4.0.
浏览器对自己“撒谎”是有历史原因的。主要原因是用户代理嗅探。Opera 是唯一将自己标识为 Opera 的浏览器,所有其他浏览器都使用 Mozilla/5.0 或较旧的 Mozilla/4.0。
The only thing you should know about this is: User agent strings cannot be trusted, feautre detection is recommended instead.
关于这一点,您应该知道的唯一一件事是:用户代理字符串不可信,建议使用 feautre 检测。
回答by mdrg
User agent strings are like that, as mentioned.
如前所述,用户代理字符串就是这样。
You haven't said that explictly, but if you are planning to use useragent string to detect the user's browser, please use some good code to do that (i.e. don't code it yourself in a hurry, you'll not get it right).
你没有明确地说,但如果你打算使用 useragent 字符串来检测用户的浏览器,请使用一些好的代码来做到这一点(即不要着急自己编写代码,你不会得到正确的)。
Here is a nice one that I've used a couple times before: Browser detect.
这是我以前使用过几次的一个很好的方法:Browser detection。
回答by Abhishek Goel
After trying everything I have finally used : http://www.useragentstring.com/
在尝试了我最终使用的一切之后:http: //www.useragentstring.com/
You can use the above website to get the formatted user agent and OS.
They have api which you can use directly...
hope it helps..!!!
您可以使用上述网站获取格式化的用户代理和操作系统。
他们有你可以直接使用的api...
希望它有帮助..!!!

