JavaScript 窗口導(dǎo)航器
Navigator 對(duì)象
JavaScript Navigator 對(duì)象包含了有關(guān)瀏覽器的相關(guān)信息。
提示:Navigator 對(duì)象雖然沒(méi)有明確的相關(guān)標(biāo)準(zhǔn),但所有瀏覽器都支持該對(duì)象。
window.navigator?對(duì)象在編寫時(shí)可不使用 window 這個(gè)前綴。
<div id="example"></div> <script> txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>"; txt+= "<p>Browser Name: " + navigator.appName + "</p>"; txt+= "<p>Browser Version: " + navigator.appVersion + "</p>"; txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>"; txt+= "<p>Platform: " + navigator.platform + "</p>"; txt+= "<p>User-agent header: " + navigator.userAgent + "</p>"; txt+= "<p>User-agent language: " + navigator.systemLanguage + "</p>"; document.getElementById("example").innerHTML=txt; </script>
警告!!!
來(lái)自 navigator 對(duì)象的信息具有誤導(dǎo)性,不應(yīng)該被用于檢測(cè)瀏覽器版本,這是因?yàn)椋?/p>
navigator 數(shù)據(jù)可被瀏覽器使用者更改
一些瀏覽器對(duì)測(cè)試站點(diǎn)會(huì)識(shí)別錯(cuò)誤
瀏覽器無(wú)法報(bào)告晚于瀏覽器發(fā)布的新操作系統(tǒng)
Navigator 對(duì)象方法
Navigator 對(duì)象有如下 2 個(gè)方法:
navigator.javaEnabled():檢測(cè)瀏覽器是否啟用了 java 支持,返回布爾值,true 表示支持。
navigator.taintEnabled():檢測(cè)瀏覽器是否啟用數(shù)據(jù)污點(diǎn)(data tainting),返回布爾值,true 表示啟用。