Home > イヌでもわかるJavaScript講座 お品書き
イヌでもわかるJavaScript講座 お品書き へ戻ります
イヌでもわかるJavaScript講座


Step.29 - ブラウザ情報の取得


いろいろなブラウザ情報を取得してみます。


Step テーマ
● navigator オブジェクト (ブラウザ情報)

実行例





リスト


<script type="text/javascript"><!--
document.write( "ブラウザ : ", navigator.appName, "</br>" );
document.write( "エージェント : ", navigator.userAgent, "</br>" );
document.write( "バージョン : ", navigator.appVersion, "</br>" );
document.write( "コードネーム : ", navigator.appCodeName, "</br>" );
document.write( "プラットフォーム : ", navigator.platform, "</br>" );
// --></script>


サンプルだけの HTMLは こちらへ

説明


ブラウザの情報は navigator オブジェクトを使います。
navigator オブジェクトには、以下のような プロパティが用意されています。

navigator.appName (ブラウザ)


navigator.userAgent (ユーザエージェント)


navigator.appVersion (バージョン)


navigator.appCodeName (コードネーム)


navigator.platform (プラットフォーム)


これらを使って、それぞれのブラウザやバージョン、OSを把握して、対応したホームページを表示してあげます。
これ以外にも プロパティやメソッドが 用意されていますが、ブラウザに互換がありません。

● navigator の プロパティ/メソッド

● IE10 (Windows8)
navigator.appCodeName = Mozilla
navigator.appMinorVersion = 0
navigator.appName = Microsoft Internet Explorer
navigator.appVersion = 5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729)
navigator.browserLanguage = ja-JP
navigator.cookieEnabled = true
navigator.cpuClass = x86
navigator.geolocation = [object Geolocation]
navigator.javaEnabled = function javaEnabled() { [native code] }
navigator.mimeTypes = [object MSMimeTypesCollection]
navigator.msDoNotTrack = 1
navigator.msLaunchUri = function msLaunchUri() { [native code] }
navigator.msManipulationViewsEnabled = true
navigator.msMaxTouchPoints = 0
navigator.msPointerEnabled = true
navigator.msSaveBlob = function msSaveBlob() { [native code] }
navigator.msSaveOrOpenBlob = function msSaveOrOpenBlob() { [native code] }
navigator.onLine = true
navigator.platform = Win32
navigator.plugins = [object MSPluginsCollection]
navigator.systemLanguage = ja-JP
navigator.taintEnabled = function taintEnabled() { [native code] }
navigator.userAgent = Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729)
navigator.userLanguage = ja-JP

● FX19 (Windows8)
navigator.addIdleObserver = function addIdleObserver() { [native code] }
navigator.appCodeName = Mozilla
navigator.appName = Netscape
navigator.appVersion = 5.0 (Windows)
navigator.battery = [object BatteryManager]
navigator.buildID = 20130307023931
navigator.cookieEnabled = true
navigator.doNotTrack = unspecified
navigator.getDeviceStorage = function getDeviceStorage() { [native code] }
navigator.geolocation = [object GeoGeolocation]
navigator.language = ja
navigator.mozCameras = null
navigator.mozConnection = [object MozConnection]
navigator.mozGetUserMediaDevices = function mozGetUserMediaDevices() { [native code] }
navigator.mozGetUserMedia = function mozGetUserMedia() { [native code] }
navigator.mozIsLocallyAvailable = function mozIsLocallyAvailable() { [native code] }
navigator.mozPower = null
navigator.mozSms = null
navigator.onLine = true
navigator.oscpu = Windows NT 6.2; WOW64
navigator.platform = Win32
navigator.product = Gecko
navigator.productSub = 20100101
navigator.registerContentHandler = function registerContentHandler() { [native code] }
navigator.registerProtocolHandler = function registerProtocolHandler() { [native code] }
navigator.removeIdleObserver = function removeIdleObserver() { [native code] }
navigator.requestWakeLock = function requestWakeLock() { [native code] }
navigator.userAgent = Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0
navigator.vendor =
navigator.vendorSub =
navigator.vibrate = function vibrate() { [native code] }

● SF5 (Windows8)
navigator.appCodeName = Mozilla
navigator.appName = Netscape
navigator.appVersion = 5.0 (Windows NT 6.2; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
navigator.cookieEnabled = true
navigator.getStorageUpdates = function getStorageUpdates() { [native code] }
navigator.geolocation = [object Geolocation]
navigator.javaEnabled = function javaEnabled() { [native code] }
navigator.language = ja-JP
navigator.mimeTypes = [object MimeTypeArray]
navigator.onLine = true
navigator.platform = Win32
navigator.plugins = [object PluginArray]
navigator.product = Gecko
navigator.productSub = 20030107
navigator.userAgent = Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
navigator.vendorSub =
navigator.vendor = Apple Computer, Inc.

● OP12 (Windows8)
navigator.appCodeName = Mozilla
navigator.appMinorVersion =
navigator.appName = Opera
navigator.appVersion = 9.80 (Windows NT 6.2; WOW64)
navigator.browserLanguage = ja
navigator.cookieEnabled = true
navigator.doNotTrack = null
navigator.getUserMedia = function getUserMedia() { [native code] }
navigator.geolocation = [object Geolocation]
navigator.isContentHandlerRegistered = function isContentHandlerRegistered() { [native code] }
navigator.isProtocolHandlerRegistered = function isProtocolHandlerRegistered() { [native code] }
navigator.javaEnabled = function javaEnabled() { [native code] }
navigator.language = ja
navigator.mimeTypes = [object MimeTypes]
navigator.onLine = true
navigator.platform = Win32
navigator.plugins = [object PluginArray]
navigator.registerContentHandler = function registerContentHandler() { [native code] }
navigator.registerProtocolHandler = function registerProtocolHandler() { [native code] }
navigator.taintEnabled = function taintEnabled() { [native code] }
navigator.unregisterContentHandler = function unregisterContentHandler() { [native code] }
navigator.unregisterProtocolHandler = function unregisterProtocolHandler() { [native code] }
navigator.userAgent = Opera/9.80 (Windows NT 6.2; WOW64) Presto/2.12.388 Version/12.14
navigator.userLanguage = ja

● あなたのブラウザ



● ユーザエージェント

ユーザエージェントの項目や サンプルは以下を参照してください。
UserAgent まとめ
みんなのブラウザ情報
みんなのブラウザ情報(旧館)


参考ステップ
Step.38 ブラウザのバージョンを取得してみましょう 

古臭いブラウザ履歴


● navigator 情報

Windows98 の NN Ver4.04 でしたら、
navigator.userAgent = Mozilla/4.04 [ja] (Win95; I)
navigator.appCodeName = Mozilla
navigator.appVersion = 4.04 [ja] (Win95; I)
navigator.appName = Netscape
navigator.language = ja
navigator.platform = Win32
navigator.plugins = [object PluginArray]
navigator.mimeTypes = [object MimeTypeArray]

Windows98 の IE Ver4.01 でしたら、
navigator.appCodeName = Mozilla
navigator.appMinorVersion = ;SP1;
navigator.appName = Microsoft Internet Explorer
navigator.appVersion = 4.0 (compatible; MSIE 4.01; Windows 98)
navigator.cookieEnabled = true
navigator.cpuClass = x86
navigator.mimeTypes = undefined
navigator.onLine = false
navigator.opsProfile = undefined
navigator.platform = Win32
navigator.plugins = undefined
navigator.systemLanguage = ja
navigator.userAgent = Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)
navigator.userLanguage = ja
navigator.userProfile = undefined

が使えます。


● navigator.userAgent 情報

Mozilla/2.0 (compatible; MSIE 3.0; Windows 95)
Mozilla/2.0 (compatible; MSIE 3.01; Windows 95)
Mozilla/2.0 (compatible; MSIE 3.02; Windows 95)
Mozilla/2.0 (compatible; MSIE 3.02; Update a; Windows 95)
Mozilla/4.0 (compatible; MSIE 4.0; Windows 95)
Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)
Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)
Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)
Mozilla/4.0 (compatible; MSIE 4.01; MSN 2.5; Windows 95)
Mozilla/4.0 (compatible; MSIE 4.01; MSN 2.5; Windows 98)
Mozilla/4.0 (compatible; MSIE 4.01; MSN 2.5; MSN 2.5; Windows 95)
Mozilla/4.0 (compatible; MSIE 4.01; MSN 2.5; MSN 2.5; Windows 98)
Mozilla/4.0 (compatible; MSIE 4.01; MSN 2.6; Windows 95)
Mozilla/4.0 (compatible; MSIE 4.01; Windows 98; ocnie4-4)
Mozilla/4.0 (compatible; MSIE 4.01; Windows 98; ocnie4-5)
Mozilla/4.0 (compatible; MSIE 4.01; Mac_PowerPC)
Mozilla/4.0 (compatible; MSIE 5.0b2; Windows 95)
Mozilla/4.0 (compatible; MSIE 5.0b2; Windows 98)
Mozilla/3.01 [ja] (Win95; I)
Mozilla/3.01 [ja]-C-MACOS8J (Macintosh; I; PPC)
Mozilla/4.01 [ja] (Win95; I)
Mozilla/4.01a [ja] (Macintosh; I; PPC)
Mozilla/4.03 [ja] (Win95; I)
Mozilla/4.03 [ja] (Macintosh; I; PPC)
Mozilla/4.04 [ja] (Win95; I)
Mozilla/4.04 [ja] (Win95; I ;Nav)
Mozilla/4.04 [ja] (WinNT; I)
Mozilla/4.04 [ja] (Macintosh; I; PPC, Nav)
Mozilla/4.05 [ja] (Win95; I)
Mozilla/4.05 [ja] (WinNT; I)
Mozilla/4.06 [ja] (Win95; I)
Mozilla/4.06 [ja] (Win98; I)
Mozilla/4.06 [ja] (WinNT; I)
Mozilla/4.06 [ja] (Macintosh; I; PPC)
Mozilla/4.5 [ja] (Win95; I)
Mozilla/4.5 [en] (Win95; I)
Mozilla/4.5 [ja] (Win98; I)
Mozilla/4.5 [ja] (WinNT; I)
Mozilla/4.5 (Macintosh; I; PPC)


 
イヌでもわかるJavaScript講座 お品書き へ戻ります