Navigator.userAgent (Property)

The identifying string for this browser.

Availability:

JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Opera - 3.0
Property/method value type:String primitive
JavaScript syntax:-navigator.userAgent

This string is returned to a web server in the USER-AGENT: header of an HTTP request. This is often logged and processed to analyze the distribution of browser types across the user base for a site.

The userAgent string contains much useful information and generally includes everything the appVersion and appName properties would have told you as well.

Here are some typical values:

Warnings:

- Null characters

- Control characters

- URL strings

- HTML

- C-Code

- JavaScript

- GIF image data

- Very large text blocks

Example code:

   // A function to normalize the user agent string
   function getBrowserType()
   {
   var myUserAgent;
   var myMajor;
   myUserAgent   = navigator.userAgent.toLowerCase();
   myMajor       = parseInt(navigator.appVersion);
   if( (myUserAgent.indexOf('mozilla')    != -1) &&
   (myUserAgent.indexOf('spoofer')    == -1) &&
   (myUserAgent.indexOf('compatible') == -1) &&
   (myUserAgent.indexOf('opera')      == -1) &&
   (myUserAgent.indexOf('webtv')      == -1)
   )
   {
   if (myMajor > 4)
   {
   return "nav6";
   }
   if (myMajor > 3)
   {
   return "nav4";
   }
   return "nav";
   }
   if (myUserAgent.indexOf("msie") != -1)
   {
   if (myMajor > 4)
   {
   return "ie5";
   }
   if (myMajor > 3)
   {
   return "ie4";
   }
   return "ie";
   }
   return "other";
   }

See also:server.agent

Property attributes:

ReadOnly