Click to Rate and Give Feedback
MSDN
MSDN Library
userAgent Property

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

Syntax

[ sUserAgent = ] object.userAgent

Possible Values

sUserAgentString that specifies a valid HTTP user agent.

The property is read-only. The property has no default value.

Remarks

The user-agent request header contains information about compatibility, the client, and the platform name. For more information about retrieving the application name, see the appName property. For more information about the platform and version, see the appVersion property.

The userAgent property dynamically returns a different value depending on the browser and platform versions.

For example, Microsoft Internet Explorer 6 returns the following string for Windows XP.

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)

Examples

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

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

Standards Information

There is no public standard that applies to this property.

Applies To

clientInformation, navigator, Navigator Constructor

See Also

About Conditional Comments
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker