UA判別
ネットスケープ4だとかの判定がなあ。
<html> <head> <title>UA判別script</title> <script type="text/javascript"> /* * UserAgentInfomation * matsuhsia hironobu * 2007-03-05 */ function UAinfo() {} UAinfo.prototype ={ userLangage: navigator.language, _userUa: navigator.userAgent, _userVersion: navigator.appVersion, is_os: '', is_ua: '', is_version: '', is_langage: '' } // OSの判別 // 古いブラウザーだと正確には取れません。 function is_os(){ var tempos = this._userUa; if( tempos.indexOf('Windows 95') >= 0 || tempos.indexOf('Win95') >= 0 ){ return 'Windows 95'; }else if( tempos.indexOf('Windows 98') >= 0 || tempos.indexOf('Win98') >= 0 ){ return 'Windows 98'; }else if( tempos.indexOf('Windows NT 5.0') >= 0 || tempos.indexOf('Windows 2000') >= 0 ){ return 'Windows 2000'; }else if( tempos.indexOf('Windows NT 5.1') >= 0|| tempos.indexOf('Windows XP') >= 0 ){ return 'Windows XP'; }else if( tempos.indexOf('Windows NT 5.2') >= 0 ){ return 'Windows 2003'; }else if( tempos.indexOf('Windows NT 6') >= 0 ){ return 'Windows Vista'; }else if( tempos.indexOf('Windows NT') >= 0 || tempos.indexOf('WinNT') >= 0 ){ return 'Windows NT'; }else if( tempos.indexOf('Mac OS X') >= 0 ){ return 'Mac OS X'; }else if( tempos.indexOf('Mac') >= 0 ){ return 'Macintosh'; }else if( tempos.indexOf('Ubuntu') >= 0 ){ return 'Ubuntu'; }else if( tempos.indexOf('Debian') >= 0 ){ return 'Debian'; }else if( tempos.indexOf('FreeBSD') >= 0 ){ return 'FreeBSD'; }else if( tempos.indexOf('SunOS') >= 0 ){ return 'SunOS'; }else if( tempos.indexOf('Linux') >= 0 ){ return 'Linux'; }else if( tempos.indexOf('PSP') >= 0 ){ return 'PSP'; } else{ return tempos; } } // UAの判別 function is_ua(){ var tempua = this._userUa; if( tempua.indexOf('Opera') >= 0 ){ return 'Opera'; }else if( tempua.indexOf('MSIE') >= 0 ){ return 'IE'; }else if( tempua.indexOf('Firefox') >= 0 ){ return 'Firefox'; }else if( tempua.indexOf('Safari') >= 0 ){ return 'Safari'; }else if( tempua.indexOf('Netscape') >= 0 ){ return 'Netscape'; }else if( tempua.indexOf('Mozilla') >= 0 ){ return 'Mozilla'; } else{ return tempua; } } // UAのバージョン // Opera、Netscapeはバージョンによって番号の書き方が違う... function is_version(){ var tempv = this._userUa; if( this.is_ua() == 'IE' ){ tempv.match(/MSIE(\/|\s)([0-9].[0-9]{1,3})/g); return RegExp.$2; }else if( this.is_ua() == 'Firefox' ){ tempv.match(/Firefox(\/|\s)([0-9].[0-9]{1,3})/g); return RegExp.$2; }else if( this.is_ua() == 'Opera' ){ tempv.match(/Opera(\/|\s)([0-9].[0-9]{1,3})/g); return RegExp.$2; }else if( this.is_ua() == 'Safari' ){ tempv.match(/Safari(\/|\s)([0-9]{1,3})/g); return RegExp.$2; }else if( this.is_ua() == 'Netscape' ){ if(tempv.match(/Netscape6(\/|\s)([0-9].[0-9]{1,3})/g)){ return RegExp.$2; }else if(tempv.match(/Netscape(\/|\s)([0-9].[0-9]{1,3})/g)){ return RegExp.$2; } } } function is_langage(){ return this.userLangage; } UAinfo.prototype.is_os = is_os; UAinfo.prototype.is_ua = is_ua; UAinfo.prototype.is_version = is_version; UAinfo.prototype.is_langage = is_langage; /* UA = new UAinfo(); alert(UA.is_ua()); alert(UA.is_os()); alert(UA.is_version()); */ // UAinfo.prototype.userUa = navigator.userAgent; // UAinfo.prototype.userVersion = navigator.appVersion; </script> </head> <body> <h1>UA判別</h1> <script type="text/javascript"> UA = new UAinfo(); document.write('UA:' + UA.is_ua() + '<br>'); document.write('OS:' + UA.is_os() + '<br>'); document.write('V :' + UA.is_version() + '<br>'); document.write('la:' + UA.is_langage() + '<br>'); </script> </body> </html>