Click to return to the DHTML, HTML     
USEMAP Attribute | useMap...     userLanguage Property     DHTML Properties    
Web Workshop  |  DHTML, HTML & CSS

userAgent Property


Retrieves a string equivalent to the HTTP user-agent request header.

Syntax

HTMLN/A
Scripting[ sUserAgent = ] navigator.userAgent

Possible Values

sUserAgentString that specifies a valid HTTP user agent.

The property is read-only with a browser-specific default value.

Remarks

The HTTP user-agent request header contains information about compatibility, the browser, and the platform name. For more information about the browser, see the appName property. For more information about the platform, see the appVersion property.

The userAgent property returns a different value depending on the browser and platform versions. For example, Microsoft® Internet Explorer 4.01 returns the following string for Microsoft ® Windows® 95.

Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)

Example

This example uses the userAgent property to specify a required platform before additional script is executed. For example, if Windows 95 is a requirement for the document, you can use a variable to determine whether the user is running the necessary operating system. The "bIs95" variable is set to true if Windows 95 is found in the userAgent value and the additional script is processed.

Sample Code

<SCRIPT>
var bIs95=false;
window.onload=fnInit;
function fnInit(){
   if(navigator.userAgent.indexOf("Windows 95")>-1){
      bIs95=true;
   }
   if(bIs95==true){
      // Process additional script.
   }
}
</SCRIPT>

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
clientInformation, navigator


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.