JavaScript 視窗導航器
Navigator 物件
JavaScript Navigator 物件包含了瀏覽器的相關資訊。
提示:Navigator 物件雖然沒有明確的相關標準,但所有瀏覽器都支援該物件。
window.navigator 物件在撰寫時可不使用 window 這個前綴。
<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>警告!!!
來自navigator 物件的資訊具有誤導性,不應該被用來偵測瀏覽器版本,這是因為:
navigator 資料可被瀏覽器使用者更改
某些瀏覽器對測試站點會識別錯誤
瀏覽器無法報告晚於瀏覽器發布的新作業系統
Navigator 對象方法
Navigator 物件有如下2 個方法:
navigator.javaEnabled():偵測瀏覽器是否啟用了java 支持,傳回布林值,true 表示支援。
navigator.taintEnabled():偵測瀏覽器是否啟用資料污點(data tainting),傳回布林值,true 表示啟用。
新建檔案
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
</head>
<body>
<div id="example"></div>
<script>
txt = "<p>浏览器代号: " + navigator.appCodeName + "</p>";
txt+= "<p>浏览器名称: " + navigator.appName + "</p>";
txt+= "<p>浏览器版本: " + navigator.appVersion + "</p>";
txt+= "<p>启用Cookies: " + navigator.cookieEnabled + "</p>";
txt+= "<p>硬件平台: " + navigator.platform + "</p>";
txt+= "<p>用户代理: " + navigator.userAgent + "</p>";
txt+= "<p>用户代理语言: " + navigator.systemLanguage + "</p>";
document.getElementById("example").innerHTML=txt;
</script>
</body>
</html>
預覽
Clear
- 課程推薦
- 課件下載
課件暫不提供下載,工作人員正在整理中,後期請多關注該課程~ 















