为什么“navigator.userAgent”在javaScript中返回String“Mozilla”。当在谷歌镀铬borwser尝试? [英] why Does "navigator.userAgent" in javaScript returns the String "Mozilla" when tried in a google chrome borwser?
问题描述
我正在开发一个javaScript代码,我想确定客户端浏览器的版本和品牌,这里是我正在使用的代码片段:
Im developing a javaScript code and I want to determine the version and brand of the client's browser, here's the piece of code I'm using to do so :
var browserName ;
function BrowserCheckin ()
{
if(navigator.userAgent.indexOf("Mozilla") > 0 )
browserName = "Mozilla" ;
if (navigator.userAgent.indexOf("MSIE") > 0 )
browserName = "InternetExplorer";
if (navigator.userAgent.indexOf("Chrome") > 0)
browserName= "Google Chrome" ;
if(navigator.userAgent.indexOf("Opera") > 0 )
browserName = "Opera" ;
document.write("<h1>" + browserName + "</h1>") ;
}
但是当我使用Google Chrome运行我的代码时,useAgent属性返回一个字符串包含:
but when i run my code using "Google Chrome" , the useAgent property returns a string containting :
Mozilla / 5.0(X11; Linux x86_64)AppleWebKit / 534.30(KHTML,如
Gecko)Chrome /12.0.742.112 Safari / 534.30
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30 "
但我不知道Mozilla / 5.0在那里做什么,任何人都有任何想法?
(还有一件事,我用Linux作为我的操作系统)
But I don't get what that "Mozilla/5.0" is doing there , anyone has any Idea ?
(and one more thing , I use Linux as my Operating System)
提前谢谢:)
推荐答案
历史原因,几乎所有浏览器(Opera除外)都将 Mozilla /
添加到其用户代理。
For historical reasons, nearly all browsers (except Opera) prepend Mozilla/
to their user agent.
例如,这里是一些常见的用户代理:
For example, here are some common user agents:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko)
Chrome/12.0.742.112 Safari/534.30 # Chrome 12
Mozilla/5.0 (X11; Linux x86_64) Gecko Firefox/5.0 # FF 5
Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US) # IE 9
Opera/9.80 (Windows NT 5.1; U; en) Presto/2.8.119 Version/11.10 # Opera 11.10
有关详细列表,请参阅< a href =http://www.useragentstring.com/pages/useragentstring.php>在线 数据库 。
For a detailed list, refer to online databases.
这篇关于为什么“navigator.userAgent”在javaScript中返回String“Mozilla”。当在谷歌镀铬borwser尝试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!