JavaScript 視窗導(dǎo)航器
Navigator 物件
JavaScript Navigator 物件包含了瀏覽器的相關(guān)資訊。
提示:Navigator 物件雖然沒有明確的相關(guān)標(biāo)準(zhǔn),但所有瀏覽器都支援該物件。
window.navigator?物件在撰寫時(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 物件的資訊具有誤導(dǎo)性,不應(yīng)該被用來(lái)偵測(cè)瀏覽器版本,這是因?yàn)椋?/p>
navigator 資料可被瀏覽器使用者更改
某些瀏覽器對(duì)測(cè)試站點(diǎn)會(huì)識(shí)別錯(cuò)誤
瀏覽器無(wú)法報(bào)告晚於瀏覽器發(fā)布的新作業(yè)系統(tǒng)
Navigator 對(duì)象方法
Navigator 物件有如下2 個(gè)方法:
navigator.javaEnabled():偵測(cè)瀏覽器是否啟用了java 支持,傳回布林值,true 表示支援。
navigator.taintEnabled():偵測(cè)瀏覽器是否啟用資料污點(diǎn)(data tainting),傳回布林值,true 表示啟用。