window对象的navigator属性引用了一个Navigator对象,代表的是浏览器的总体信息,navigator很多时候用来判断浏览器的类型,Navigator对象主要有五个主要属性:appName,appVersion,userAgent,appCodeName,platform,在不同浏览器中输出这些浏览器信息会发现很有有意思的东西:
代码:
<
script
>
for
(var i
in
window.navigator)
{
document.write(i
+
"
=
"
+
window.navigator[i]
+
"
<br/>
"
);
}
</
script
>
在不同浏览器中的结果:
浏览器 | 运行结果 |
IE | appCodeName = Mozilla appName = Microsoft Internet Explorer appMinorVersion = beta cpuClass = x86 platform = Win32 plugins = [object] opsProfile = null userProfile = null systemLanguage = zh-cn userLanguage = zh-cn appVersion = 5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) userAgent = Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E) onLine = true cookieEnabled = true mimeTypes = |
Firefox | appCodeName = Mozilla appName = Netscape appVersion = 5.0 (Windows; zh-CN) language = zh-CN mimeTypes = [object MimeTypeArray] platform = Win32 oscpu = Windows NT 6.1 vendor = vendorSub = product = Gecko productSub = 20101203 plugins = [object PluginArray] securityPolicy = userAgent = Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 cookieEnabled = true onLine = true buildID = 20101203075014 javaEnabled = function javaEnabled() { [native code] } taintEnabled = function taintEnabled() { [native code] } preference = function preference() { [native code] } geolocation = [object GeoGeolocation] registerContentHandler = function registerContentHandler() { [native code] } registerProtocolHandler = function registerProtocolHandler() { [native code] } mozIsLocallyAvailable = function mozIsLocallyAvailable() { [native code] } |
Chrome | language = zh-CN product = Gecko mimeTypes = [object DOMMimeTypeArray] appVersion = 5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.14 (KHTML, like Gecko) Chrome/10.0.603.3 Safari/534.14 plugins = [object DOMPluginArray] onLine = true platform = Win32 vendor = Google Inc. appCodeName = Mozilla cookieEnabled = true geolocation = [object Geolocation] appName = Netscape productSub = 20030107 userAgent = Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.14 (KHTML, like Gecko) Chrome/10.0.603.3 Safari/534.14 vendorSub = javaEnabled = function javaEnabled() { [native code] } getStorageUpdates = function getStorageUpdates() { [native code] } true |
Safri | geolocation = [object Geolocation] cookieEnabled = true language = zh-CN productSub = 20030107 product = Gecko appCodeName = Mozilla mimeTypes = [object MimeTypeArray] vendorSub = vendor = Apple Computer, Inc. platform = Win32 appName = Netscape appVersion = 5.0 (Windows; U; Windows NT 6.1; zh-CN) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4 userAgent = Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4 plugins = [object PluginArray] onLine = true javaEnabled = function javaEnabled() { [native code] } getStorageUpdates = function getStorageUpdates() { [native code] } registerProtocolHandler = function registerProtocolHandler() { [native code] } registerContentHandler = function registerContentHandler() { [native code] } |
Opera | appCodeName = Mozilla appMinorVersion = appName = Opera appVersion = 9.80 (Windows NT 6.1; U; zh-cn) browserLanguage = zh-cn cookieEnabled = true geolocation = [object Geolocation] language = zh-cn mimeTypes = [object MimeTypes] onLine = true platform = Win32 plugins = [object PluginArray] userAgent = Opera/9.80 (Windows NT 6.1; U; zh-cn) Presto/2.6.37 Version/10.70 userLanguage = zh-cn javaEnabled = function javaEnabled() { [native code] } taintEnabled = function taintEnabled() { [native code] } |
搜狗浏览器(IE) | appCodeName = Mozilla appName = Microsoft Internet Explorer appMinorVersion = beta cpuClass = x86 platform = Win32 plugins = [object] opsProfile = null userProfile = null systemLanguage = zh-cn userLanguage = zh-cn appVersion = 4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0) userAgent = Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0) onLine = true cookieEnabled = true mimeTypes = |
搜狗浏览器(webkit) | language = zh-CN product = Gecko mimeTypes = [object DOMMimeTypeArray] appVersion = 5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.33 Safari/534.3 SE 2.X MetaSr 1.0 plugins = [object DOMPluginArray] onLine = true platform = Win32 vendor = Google Inc. appCodeName = Mozilla cookieEnabled = true geolocation = [object Geolocation] appName = Netscape productSub = 20030107 userAgent = Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.33 Safari/534.3 SE 2.X MetaSr 1.0 vendorSub = javaEnabled = function javaEnabled() { [native code] } getStorageUpdates = function getStorageUpdates() { [native code] } |
遨游(IE) | appCodeName = Mozilla appName = Microsoft Internet Explorer appMinorVersion = beta cpuClass = x86 platform = Win32 plugins = [object] opsProfile = null userProfile = null systemLanguage = zh-cn userLanguage = zh-cn appVersion = 4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E) userAgent = Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E) onLine = true cookieEnabled = true mimeTypes = |
遨游(webkit) | language = zh-CN product = Gecko mimeTypes = [object MimeTypeArray] appVersion = 5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.9 (KHTML, like Gecko) Maxthon/3.0 Safari/533.9 plugins = [object PluginArray] onLine = true platform = Win32 vendor = Google Inc. appCodeName = Mozilla cookieEnabled = true appName = Netscape productSub = 20030107 userAgent = Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.9 (KHTML, like Gecko) Maxthon/3.0 Safari/533.9 vendorSub = javaEnabled = function javaEnabled() { [native code] } getStorageUpdates = function getStorageUpdates() { [native code] } registerProtocolHandler = function registerProtocolHandler() { [native code] } registerContentHandler = function registerContentHandler() { [native code] } |
360极速浏览器(IE) | appCodeName = Mozilla appName = Microsoft Internet Explorer appMinorVersion = beta cpuClass = x86 platform = Win32 plugins = [object] opsProfile = null userProfile = null systemLanguage = zh-cn userLanguage = zh-cn appVersion = 4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; TheWorld) userAgent = Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; TheWorld) onLine = true cookieEnabled = true mimeTypes = |
360极速浏览器(webkit) | language = zh-CN product = Gecko mimeTypes = [object DOMMimeTypeArray] appVersion = 5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7 plugins = [object DOMPluginArray] onLine = true platform = Win32 vendor = Google Inc. appCodeName = Mozilla cookieEnabled = true geolocation = [object Geolocation] appName = Netscape productSub = 20030107 userAgent = Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7 vendorSub = javaEnabled = function javaEnabled() { [native code] } getStorageUpdates = function getStorageUpdates() { [native code] } |
对比之下发现有几件很有意思的事情:
1.不同浏览器的Navigator属性差异够大的,所有的浏览器都有几个通用的属性:appName,appVersion,userAgent,appcodeName,platform,onLine,cookieEnabled,mimeTypes。浏览器都有着几个属性,但其他属性就不一样,这点当使用到navigator属性时要注意,很容易出现兼容性问题,要么出现undefined,要么干脆就跑不了
2.所有浏览器的appcodeName都是"Mozilla",查了下资料,appcodeName是浏览器的代码名,netscape用代码名"Mozilla”作为属性值,为了兼容,IE也采用了”Mozilla“作为这一个属性值,感觉很囧,估计是这个原因导致后面的浏览器的appcodeName都是"Mozilla"
3.gecko和webkit内核的浏览器的appName都是"Netscape",而且gecko和webkit浏览器都有一个product属性,而属性值都为"Gecko",当年IE和网景两家浏览器大战打得够厉害,虽然结果网景落败,但gecko毕竟开源,而且网景算是最早一家弄出真正的浏览器的,弄出了很多浏览器的标准,opera一直小打小闹,影响力不够,而且和IE一样是非开源,webkit开发的时候肯定是借鉴了不少gecko的东西,而且google开发chrome之前一直是大力支持mozilla的,每年给mozilla提供了很大量的资金。同为开源,webkit受gecko的影响也很正常
4,国产的几款浏览器中(纯IE内的就不用说了),搜狗,遨游,360算是做得比较好的,腾讯的那个和这几款相比各方面的性能还是很有点差距,几款浏览器给我的印象是搜狗的浏览器的用户体验做得最好,他的代理服务器,下载,页面声音控制等功能相当不错,遨游呢,国内老牌的浏览器厂商,浏览器方面技术实力很强,浏览器的整体风格给我的感觉和其他几款相比稍微有点另类,其他几款继承chrome的风格,双内核版本的和他们IE内核版本的风格差距比较大,但遨游的整体风格继承自遨游IE版本,虽然现在一些功能还不完整。从appversion的参数来看,搜狗和360两家都有chrome的影子,搜狗是采用的chrome的6.0,360采用的是7.0,chrome版本更新的太快,短短几年就从1.0到现在的10.0了,遨游的appversion中压根看不到chrome的影子,某种程度上也说明对于内核裁剪修改的比较厉害,在浏览器上面花了很大功夫,三家中,感觉最好用的是搜狗,遨游的技术实力强一些,360那货,copy chrome的太厉害了,浏览器上面花费功夫比较少,很少用这玩意,强烈鄙视。