platform,userAgent,appNameの値から、文字列検索でブラウザの種類を識別できる(appNameは実際の利用価値がないことがわかる)。
if (typeof gUaLow == 'undefined') var gUaLow = gNavi.userAgent.toLowerCase();
var UserAgent = {
Version: '1.4.a',
Description: 'HTTPユーザーエージェント文字列の解析。ブラウザの種別とOS種別を解析して文字列で返す。',
// ブラウザ種別の文字列を取得します
getUserAgent: function () {
var str = "ブラウザ不明";
// Opera
if (gUaLow.match(/opera/)) {
if (gUaLow.match(/blackberry/)) {
if (gUaLow.match(/version\/([\.\d]+)/)) {
str = "BlackBerry Opera " + RegExp.$1;
}
}
else if (gUaLow.match(/version\/([\.\d]+)/)) { // Operaの場合、MSIE句があるので注意
str = "Opera " + RegExp.$1;
}
else if (gUaLow.match(/opera ([\.\d]+)/)) {
str = "Opera " + RegExp.$1;
}
else if (gUaLow.match(/opera\/([\.\d]+)/)) {
str = "Opera " + RegExp.$1;
}
else
str = "Opera";
}
// BlackBerry (非Opera系)
else if (gUaLow.match(/blackberry/)) {
if (gUaLow.match(/blackberry\d\/([\.\d]+)/)) {
str = "BlackBerry " + RegExp.$2;
}
else
str = "BlackBerry";
}
// Konqueror (Linux系)
else if (gUaLow.match(/konqueror\/([\.\d]+)/)) {
str = "Konqueror " + RegExp.$1;
}
// DreamPassport (ゲーム用)
else if (gUaLow.match(/dreampassport\/([\.\d]+)/)) {
str = "DreamPassport " + RegExp.$1;
}
// iCab (Mac)
else if (gUaLow.match(/icab j\/([\.\d]+)/)) {
str = "iCab " + RegExp.$1;
}
else if (gUaLow.match(/icab\/([\.\d]+)/)) {
str = "iCab " + RegExp.$1;
}
// Adobe Acrobat WebCapture
else if (gUaLow.match(/webcapture ([\.\d]+)/)) {
str = "Adobe Acrobat " + RegExp.$1;
}
// Adobe Bridge CS3
else if (gUaLow.match(/bridge\/([\.\d]+)/)) {
str = "Adobe Bridge CS3 " + RegExp.$1;
}
// Trident
else if (gUaLow.match(/lunascape ([\.\d]+)/)) {
str = "Lunascape " + RegExp.$1;
}
else if (gUaLow.match(/sleipnir\/([\.\d]+)/)) {
str = "Sleipnir " + RegExp.$1;
}
else if (gUaLow.match(/woopie/)) {
str = "Woopie ";
}
else if (gUaLow.match(/msie ([\.\d]+)/)) {
str = "Microsoft Internet Explorer " + RegExp.$1;
if (gUaLow.indexOf("windows phone") === -1) {
str = " Windows Phone ";
}
else if (gUaLow.match(/iemobile([\.\d]+)/)) {
str = " IEMobile " + RegExp.$1;
}
else if (gUaLow.match(/opera ([\.\d]+)/)) {
str = " Opera " + RegExp.$1;
}
else {
str = " or Else.";
}
}
// AppleWebKit
else if (gUaLow.match(/applewebkit/)) {
if (gUaLow.match(/mobile/) && gUaLow.match(/safari/)) {
if (gUaLow.match(/version\/([\.\d]+)/)) {
str = "Mobile Safari/" + RegExp.$1;
}
else {
str = "Mobile Safari";
}
}
else if (gUaLow.match(/chrome\/([\.\d]+)/)) {
str = "Chrome " + RegExp.$1;
}
else if (gUaLow.match(/shiira\/([\.\d]+)/)) {
str = "Shiira " + RegExp.$1;
}
else if (gUaLow.match(/safari/)) {
gUaLow.match(/version\/([\.\d]+)/);
str = "Safari " + RegExp.$1;
}
}
// Gecko / Mozilla
else if (gUaLow.match(/mozilla\/(4\.[5678]\d?)/)) {
str = "Netscape Communicator " + RegExp.$1;
}
else if (gUaLow.match(/netscape6?\/([\.\d]+)/)) {
str = "Netscape Navigator " + RegExp.$1;
}
else if (gUaLow.match(/navigator?\/([\.\d]+)/)) {
str = "Netscape Navigator " + RegExp.$1;
}
else if (gUaLow.match(/gecko/)) {
if (gUaLow.match(/cometbird\/([\.\d]+)/)) {
str = "CometBird " + RegExp.$1;
}
else if (gUaLow.match(/flock\/([\.\d]+)/)) {
str = "Flock " + RegExp.$1;
}
else if (gUaLow.match(/seamonkey\/([\.\d]+)/)) {
str = "SeaMonkey " + RegExp.$1;
}
else if (gUaLow.match(/(firebird|firefox)\/([\.\d]+)/)) {
str = "Mozilla " + RegExp.$1 + " " + RegExp.$2;
}
else if (gUaLow.match(/thunderbird\/([\.\d]+)/)) {
str = "Mozilla Thunderbird " + RegExp.$1;
}
else if (gUaLow.match(/rv:([\.\d]+)/)) {
str = "Mozilla " + RegExp.$1;
}
else {
str = "Mozilla ?";
}
}
// SoftBank | Vodafone
else if (gUaLow.match(/(softbank|vodafone)\/([\.\d)/)) {
str = RegExp.$1 + " " + RegExp.$2;
if (gUaLow.match(/netfront([\.\d]+)/)) {
str += "NetFront/" + RegExp.$1;
}
else if (gUaLow.match(/up\.browser([\.\d]+)/)) {
str += "UP.Browser/" + RegExp.$1;
}
}
if (AugusAjax.BrowserEngine.Trident) return "Trident Engine: "+str;
else if (AugusAjax.BrowserEngine.Gecko) return "Gecko Engine: "+str;
else if (AugusAjax.BrowserEngine.WebKit) return "WebKit Engine: "+str;
else if (AugusAjax.BrowserEngine.Presto) return "Presto Engine: "+str;
else return "Unknown Engine:"+str;
return str;
}
}
ここでは、実際に何が表示されているか調べてみました(モバイル系はネット調査のみ)。
動作環境は以下の通りです。
Trident
ユーザーエージェント:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Lunascape 6.4.6.23632)Gecko
ユーザーエージェント:Mozilla/5.0 (Windows; U; Windows NT 6.1; ja; rv:1.9.2.16) Gecko/20110406 Firefox/3.6.16 Lunascape/6.4.6.23632WebKit
ユーザーエージェント:Mozilla/5.0 (Windows; U; Windows NT 6.1; ja-JP) AppleWebKit/533.3 (KHTML, like Gecko) Lunascape/6.4.6.23632 Safari/533.3詳細は、http://www.kagua.biz/android/ualist.htmlにあるよ。
2009年夏にWebKitエンジン採用のニュースが出たが、どう表示されるのだろう?
他多数あるので割愛…。docomoサイトに端末スペック一覧にPDFで提供されています。