navigator 是 window 的特徵,可以用 window.navigator;也可以省略 window,直接用 navigator。
- 程式用法:
<ol>
<script type='text/javascript'>
for( k in navigator )
document.write( '<li>'+ k +' : '+ navigator[k] );
</script>
</ol> - 執行結果:
- vendorSub :
- productSub : 20030107
- vendor : Google Inc.
- maxTouchPoints : 0
- scheduling : [object Scheduling]
- userActivation : [object UserActivation]
- doNotTrack : null
- geolocation : [object Geolocation]
- connection : [object NetworkInformation]
- plugins : [object PluginArray]
- mimeTypes : [object MimeTypeArray]
- pdfViewerEnabled : false
- webkitTemporaryStorage : [object DeprecatedStorageQuota]
- webkitPersistentStorage : [object DeprecatedStorageQuota]
- windowControlsOverlay : [object WindowControlsOverlay]
- hardwareConcurrency : 64
- cookieEnabled : true
- appCodeName : Mozilla
- appName : Netscape
- appVersion : 5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
- platform : Linux x86_64
- product : Gecko
- userAgent : Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
- language : en-US
- languages : en-US
- onLine : true
- webdriver : true
- getGamepads : function getGamepads() { [native code] }
- javaEnabled : function javaEnabled() { [native code] }
- sendBeacon : function sendBeacon() { [native code] }
- vibrate : function vibrate() { [native code] }
- ink : [object Ink]
- mediaCapabilities : [object MediaCapabilities]
- mediaSession : [object MediaSession]
- permissions : [object Permissions]
- 上面列出 navigator 的成員,不同瀏覽器會有差異。
存有當下瀏覽器的內部編碼名稱。
- 程式用法:
<script type='text/javascript'>
document.write( navigator.appCodeName );
</script> - 執行結果:
Mozilla
- IE, Firefox, Safari, Chrome 都顯示 ”Mozilla”。
存有瀏覽器的正式名稱。
- 程式用法:
<script type='text/javascript'>
document.write( navigator.appName );
</script> - 執行結果:
Netscape
- IE 顯示 ”Microsoft Internet Explorer”;Firefox, Safari, Chrome 都顯示 ”Netscape”。
存有瀏覽器的版本字串。
- 程式用法:
<script type='text/javascript'>
document.write( navigator.appVersion );
</script> - 執行結果:
5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
- 各個瀏覽器的輸出都不同。
存有瀏覽器的識別名。限 Firefox 使用。
- 程式用法:
<script type='text/javascript'>
document.write( navigator.buildID );
</script> - 執行結果:
undefined
存有一個布林值,表示瀏覽器的 cookie 是否啟動?
- 程式用法:
<script type='text/javascript'>
document.write( navigator.cookieEnabled );
</script> - 執行結果:
true
存有瀏覽器的語言版本字串。IE 使用 systemLanguage, userLanguage;Firefox, Safari, Chrome 使用 language。
- 程式用法:
<script type='text/javascript'>
if( navigator.appName == 'Netscape' )
document.write( navigator.language );
else
document.write( navigator.systemLanguage
+'<br />'+ navigator.userLanguage );
</script> - 執行結果:
en-US
存放一個清單,內有瀏覽器支援的 MIME 型態。MimeType 物件的成員有:description, enabledPlugin, suffixes, type。
- 程式用法:
<script type='text/javascript'>
document.write( navigator.mimeTypes.length +'<br />');
document.write( navigator.mimeTypes +'<br />');
for(k in navigator.mimeTypes[0] )
document.write( k +' : '+ navigator.mimeTypes[0][k] +'<br />');
</script> - 執行結果:
0
[object MimeTypeArray]
- IE 無此項;Firefox, Safari, Chrome 都有支援,但是輸出不同。