JavaScriptでのユーザーエージェント(UserAgent)の取得 - JavaScript

JavaScriptでユーザーエージェントの取得するコードを紹介します。

概要

JavaScriptでユーザーエージェントを取得する場合は"navigator.userAgent"を用います。

記述例

navigator.userAgent
補足
ネームスペースを含めた名前は "window.navigator.userAgent"です。

コード

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
  ユーザーエージェント:
  <script type="text/javascript">
  <!--
  document.write(navigator.userAgent);
  // -->
  </script>
</body>
</html>

実行結果

HTMLファイルを表示します。下図の画面が表示され、ユーザーエージェントが取得できています。

このページのキーワード
  • JSでのユーザーエージェント(UserAgent)の取得
著者
iPentecのメインプログラマー
C#, ASP.NET の開発がメイン、少し前まではDelphiを愛用
最終更新日: 2024-05-21
改訂日: 2024-05-21
作成日: 2013-06-14
iPentec all rights reserverd.