navigator.userAgent

書式

navigator.userAgent

説明

ユーザーエージェント名を返します。ブラウザの判別を行うにはuserAgentプロパティを使って調べます。ただし、userAgentの文字列も自由に設定できるブラウザがあるため正確な判別を行うには限界があります。なお、Operaの場合はwindow.operaプロパティを調べることにより判別することができます。

サンプルコード [実行]

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<script type="text/javascript"><!--
window.onload = function() {
var txt = navigator.userAgent;
document.getElementById("result").innerHTML = txt;
}
// --></script>
</head>
<body>
<div id="result"></div>
</body>
</html>