JavaScriptを使ったエージェント名によるブラウザ判定  <要:後半部確認>

各ブラウザはどのようなエージェント名を返すか確認するJavascript

<script>
document.write(navigator.userAgent);
</script>

テスト結果はそれぞれ
IE
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;
AskTbFXTV5/5.12.2.16749; .NET4.0E)

FireFox
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.1) Gecko/20100101
Firefox/6.0.1

Opera
Opera/9.80 (Windows NT 6.1; U; en) Presto/2.9.168
Version/11.50

Chrome
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML,
like Gecko) Chrome/13.0.782.218 Safari/535.1

Safari
Mozilla/5.0 (Windows; U; Windows NT 6.1; ja-JP) AppleWebKit/
533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1

JavaScriptでuserAgentよるブラウザ判定(IE, iPad, iPhone, iPod,
Chrome, Firefox, etc…)する処理

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="referrer" content="origin">
<title>JavaScript</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')</script>
</head>
<body>
<script>
/*
 * if.useragent.js v0.1
 * info: http://company.miyanavi.net/archives/808
 * auther: miyanavi
 * licence: MIT
 *
 */
var uaName = 'unknown';
var userAgent = window.navigator.userAgent.toLowerCase();
var appVersion = window.navigator.appVersion.toLowerCase();
 
if (userAgent.indexOf('msie') != -1) {
  uaName = 'ie';
  if (appVersion.indexOf('msie 6.') != -1) {
    uaName = 'ie6';
  } else if (appVersion.indexOf('msie 7.') != -1) {
    uaName = 'ie7';
  } else if (appVersion.indexOf('msie 8.') != -1) {
    uaName = 'ie8';
  } else if (appVersion.indexOf('msie 9.') != -1) {
    uaName = 'ie9';
  } else if (appVersion.indexOf('msie 10.') != -1) {
    uaName = 'ie10';
  }
} else if (userAgent.indexOf('chrome') != -1) {
  uaName = 'chrome';
} else if (userAgent.indexOf('ipad') != -1) {
  uaName = 'ipad';
} else if (userAgent.indexOf('ipod') != -1) {
  uaName = 'ipod';
} else if (userAgent.indexOf('iphone') != -1) {
  uaName = 'iphone';
  var ios = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
  uaName = [parseInt(ios[1], 10), parseInt(ios[2], 10), parseInt(ios[3] || 0, 10)];
} else if (userAgent.indexOf('safari') != -1) {
  uaName = 'safari';
} else if (userAgent.indexOf('gecko') != -1) {
  uaName = 'gecko';
} else if (userAgent.indexOf('opera') != -1) {
  uaName = 'opera';
} else if (userAgent.indexOf('android') != -1) {
  uaName = 'android';
} else if (userAgent.indexOf('mobile') != -1) {
  uaName = 'mobile';
};
 
document.write(uaName);
 
</script>
<hr>
ブラウザ情報<br>
<tt style="font-size: 12px;">
[名]<br><script>document.write(navigator.appName)</script><br>
[コード名]<br><script>document.write(navigator.appCodeName)</script><br>
[プラットフォームのタイプ]<br>
<script>document.write(navigator.platform)</script><br>
[使用言語]<br><script>document.write(navigator.language)</script><br>
[バージョン]<br><script>document.write(navigator.appVersion)</script><br>
[ユーザエージェント]<br><script>document.write(navigator.userAgent)</script><br>
</tt>
</body>
</html>

browser_Share

参照サイト
http://winofsql.jp/VA003334/infoboard.php?id=070828100942&mid=sjscript&pid=3

カテゴリー: ウェブサイト作成の秘訣 タグ: , パーマリンク