JS判斷瀏覽器之Navigator對(duì)象
更新時(shí)間:2007年01月28日 00:00:00 作者:
The Navigator Object
導(dǎo)航對(duì)象
The JavaScript Navigator object contains all information about the visitor's browser. We are going to look at two properties of the Navigator object:
JS導(dǎo)航對(duì)象包含所有有關(guān)訪問這者瀏覽器的信息。我們將看看兩個(gè)導(dǎo)航對(duì)象的產(chǎn)物:
appName - holds the name of the browser
appName - 含瀏覽器的名稱
appVersion - holds, among other things, the version of the browser
appVersion - 瀏覽器版本
Example
舉例
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
The variable browser in the example above holds the name of the browser, i.e. "Netscape" or "Microsoft Internet Explorer".
上面例子中變量brower(瀏覽器)被賦加了瀏覽器的名稱,網(wǎng)景或是IE(或其他)
The appVersion property in the example above returns a string that contains much more information than just the version number, but for now we are only interested in the version number. To pull the version number out of the string we are using a function called parseFloat(), which pulls the first thing that looks like a decimal number out of a string and returns it.
上面例子中的appVersion屬性返回一串包含比版本號(hào)更多的信息字符,但現(xiàn)在我們只要版本號(hào)。要從字符串中提出版本號(hào)我們使用一個(gè)叫parseFloat()的函數(shù)來返回?cái)?shù)字。
IMPORTANT! The version number is WRONG in IE 5.0 or later! Microsoft start the appVersion string with the numbers 4.0. in IE 5.0 and IE 6.0!!! Why did they do that??? However, JavaScript is the same in IE6, IE5 and IE4, so for most scripts it is ok.
(有關(guān)JS返回IE版本號(hào)的問題)
Example
舉例
The script below displays a different alert, depending on the visitor's browser:
根據(jù)訪問者的瀏覽器,(不同的瀏覽器)下面的腳本將顯示不同的警示:
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
導(dǎo)航對(duì)象
The JavaScript Navigator object contains all information about the visitor's browser. We are going to look at two properties of the Navigator object:
JS導(dǎo)航對(duì)象包含所有有關(guān)訪問這者瀏覽器的信息。我們將看看兩個(gè)導(dǎo)航對(duì)象的產(chǎn)物:
appName - holds the name of the browser
appName - 含瀏覽器的名稱
appVersion - holds, among other things, the version of the browser
appVersion - 瀏覽器版本
Example
舉例
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
The variable browser in the example above holds the name of the browser, i.e. "Netscape" or "Microsoft Internet Explorer".
上面例子中變量brower(瀏覽器)被賦加了瀏覽器的名稱,網(wǎng)景或是IE(或其他)
The appVersion property in the example above returns a string that contains much more information than just the version number, but for now we are only interested in the version number. To pull the version number out of the string we are using a function called parseFloat(), which pulls the first thing that looks like a decimal number out of a string and returns it.
上面例子中的appVersion屬性返回一串包含比版本號(hào)更多的信息字符,但現(xiàn)在我們只要版本號(hào)。要從字符串中提出版本號(hào)我們使用一個(gè)叫parseFloat()的函數(shù)來返回?cái)?shù)字。
IMPORTANT! The version number is WRONG in IE 5.0 or later! Microsoft start the appVersion string with the numbers 4.0. in IE 5.0 and IE 6.0!!! Why did they do that??? However, JavaScript is the same in IE6, IE5 and IE4, so for most scripts it is ok.
(有關(guān)JS返回IE版本號(hào)的問題)
Example
舉例
The script below displays a different alert, depending on the visitor's browser:
根據(jù)訪問者的瀏覽器,(不同的瀏覽器)下面的腳本將顯示不同的警示:
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
您可能感興趣的文章:
- Javascript判斷對(duì)象是否相等實(shí)現(xiàn)代碼
- js中判斷Object、Array、Function等引用類型對(duì)象是否相等
- js中判斷對(duì)象是否為空的三種實(shí)現(xiàn)方法
- JS判斷對(duì)象是否存在的10種方法總結(jié)
- JavaScript 判斷判斷某個(gè)對(duì)象是Object還是一個(gè)Array
- javascript檢測(cè)對(duì)象中是否存在某個(gè)屬性判斷方法小結(jié)
- Javascript中判斷變量是數(shù)組還是對(duì)象(array還是object)
- JS/Jquery判斷對(duì)象為空的方法
- 簡(jiǎn)單方法判斷JavaScript對(duì)象為null或者屬性為空
- js判斷對(duì)象是否是某一類型
- JavaScript中判斷對(duì)象類型的幾種方法總結(jié)
- js實(shí)現(xiàn)數(shù)組去重、判斷數(shù)組以及對(duì)象中的內(nèi)容是否相同
- JS判斷兩個(gè)對(duì)象內(nèi)容是否相等的方法示例
相關(guān)文章
JavaScript中Function()函數(shù)的使用教程
這篇文章主要介紹了JavaScipt中Function()函數(shù)的使用教程,是JavaScipt入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-06-06IE6瀏覽器下resize事件被執(zhí)行了多次解決方法
在IE瀏覽器下,一次resize事件被執(zhí)行了多次,這是IE6和IE7的一個(gè)比較廣為認(rèn)知的問題,這個(gè)問題在這兩個(gè)版本的瀏覽器中表現(xiàn)有所不同,通常IE6下會(huì)比IE7下更為糟糕,接下來將介紹解決方法,需要的朋友可以參考下2012-12-12nodejs的require模塊(文件模塊/核心模塊)及路徑介紹
在nodejs中,模塊大概可以分為核心模塊和文件模塊,核心模塊是被編譯成二進(jìn)制代碼,引用的時(shí)候只需require表示符即可,文件模塊,則是指js文件、json文件或者是.node文件2013-01-01Ruffy javascript 學(xué)習(xí)筆記
Ruffy javascript 學(xué)習(xí)筆記2009-11-11JavaScript arguments 多參傳值函數(shù)
在一個(gè)函數(shù)體內(nèi),標(biāo)識(shí)符arguments引用了arguments對(duì)象的一個(gè)特殊屬性??梢园凑諗?shù)目(而不是名字)獲取傳遞給函數(shù)的參數(shù)值。2010-10-10JavaScript中window、doucment、body的解釋
JavaScript中window、doucment、body是什么意思呢,下面為大家做個(gè)介紹,不知道的朋友可以參考下2013-08-08Web Inspector:關(guān)于在 Sublime Text 中調(diào)試Js的介紹
本篇文章小編將為大家介紹,Web Inspector:關(guān)于在 Sublime Text 中調(diào)試Js的介紹。需要的朋友可以參考一下2013-04-04