转自:http://msdn.microsoft.com/workshop/author/dhtml/overview/aboutuseragent.asp
This topic describes the user-agent string, which identifies your browser and certain system details to servers hosting the Web sites you visit. The topic also shows how to view your user -agent string, summarizes tokens used by recent versions of Microsoft Internet Explorer, and documents registry keys that effect the user-agent string.
This topic contains the following sections.
- Introduction
- Understanding the User-Agent String
- Viewing the User-Agent String
- Internet Explorer User-Agent Tokens
- User-Agent Registry Keys
Introduction
When you visit a Web page, your browser sends the user-agent string to the server hosting the site you're visiting. This string indicates which browser you're using, its version number, and details about your system, such as operating system and version. The Web server can use this information to provide content tailored for your specific browser.
Because certain third-parties add additional details to the user- agent string, it's important to understand the user-agent string. This article explains the user-agent string, lists the values from recent Internet Explorer versions, and documents registry keys that modify the user-agent string.
Understanding the User-Agent String
When you request Web pages, your browser sends a number of headers to the server hosting the site you're visiting. Each header contains details that help the server determine the best way to provide the information you've requested. One header, called the user-agent, identifies the application requesting the information from the server. In addition, the user-agent string can contain optional details within parenthesis. Optional details are called tokens and vary between programs. Internet Explorer uses tokens to describe additional details about your computer system.
The following figure shows a sample user-agent string reported by Internet Explorer and highlights its tokens.
For historical reasons, Internet Explorer identifies itself as a Mozilla 4.0 browser.
The sample user-agent string contains three tokens.
-
The Compatibility flag ("compatible") is used by most modern browsers; it indicates that Internet Explorer is compatible with a common set of features.
-
The Version token specifically identifies the browser and contains the version number. The version token in the example ("MSIE 7.0") identifies Windows Internet Explorer 7.
-
The Platform token ("Windows NT 6.0") identifies your operating system and contains its version number. The example token indicates Microsoft Windows Vista.
In the example, Internet Explorer is the user agent. However, other programs also provide user-agent strings when contacting servers over the Internet. For example, the Windows RSS Platform provides the following user-agent header when requesting RSS data.
Windows-RSS-Platform/1.0 (MSIE 7.0; Windows NT 5.1)
Like the user-agent string of Internet Explorer, this provides details about your system.
Alternate tokens can appear in the user-agent string for a number of reasons; these usually identify optional features installed on your system. For example, an "SV1" token appears in the user- agent strings of Windows XP users who have installed Windows XP Service Pack 2 (SP2). It is also important to note that certain third-parties modify the user-agent string for their own purposes.
For information on other headers communicated to Web servers, see The World Wide Web Consortium's RFC 2616, Section 14: Header Field Definitions .
Viewing the User-Agent String
To view your browser's user-agent string, type the following into the address bar.
javascript:alert(navigator.userAgent)
Please note that this is case-sensitive.
When you do this, a dialog box displays your user-agent string, as shown in the following figure.
Internet Explorer User-Agent Tokens
This section summarizes the tokens used by recent versions of Internet Explorer, which places three tokens in the user-agent string by default.
- Version tokens
- Platform tokens
- Feature tokens
The following table lists the version tokens used in recent versions of Internet Explorer. In general, version tokens begin with MSIE and are followed by the version number of the browser. Many pre-release versions append the letter "b" to the version number.
Version token | Description |
---|---|
MSIE 7.0 | Internet Explorer 7 |
MSIE 7.0b | Internet Explorer 7 (Beta 1 pre-release only) |
MSIE 6.0 | Internet Explorer 6 |
MSIE 6.0b | Internet Explorer 6 (pre-release) |
MSIE 5.5 | Internet Explorer 5.5 |
MSIE 5.01 | Internet Explorer 5.01 |
MSIE 5.0 | Internet Explorer 5 |
MSIE 5.0b1 | Internet Explorer 5 (pre-release) |
MSIE 4.01 | Internet Explorer 4.01 |
Platform tokens describe your operating system; the following table lists Internet Explorer platform tokens for the last several versions of Windows.
Platform token | Description |
---|---|
Windows NT 6.0 | Windows Vista |
Windows NT 5.2 | Windows Server 2003; Windows XP x64 Edition |
Windows NT 5.1 | Windows XP |
Windows NT 5.01 | Windows 2000, Service Pack 1 (SP1) |
Windows NT 5.0 | Windows 2000 |
Windows NT 4.0 | Microsoft Windows NT 4.0 |
Windows 98; Win 9x 4.90 | Windows Millennium Edition (Windows Me) |
Windows 98 | Windows 98 |
Windows 95 | Windows 95 |
Windows CE | Windows CE |
Certain optional components can also modify the user-agent string; the following table shows common ones. Be aware that many third parties also modify the user- agent string. Because of this, a comprehensive list is not possible. If you find additional tokens in your user-agent string, you should investigate them in more detail.
Token | Description |
---|---|
.NET CLR | .NET Framework common language runtime, followed by the version number |
SV1 | Internet Explorer 6 with enhanced security features. (Windows XP SP2 and Windows Server 2003 only) |
Tablet PC | Tablet services are installed; number indicates the version number |
Win64; IA64 | System has a 64-bit processor (Intel) |
Win64; x64 | System has a 64-bit processor (AMD) |
WOW64 | A 32-bit version of Internet Explorer is running on a 64-bit processor. |
User-Agent Registry Keys
When you install certain Windows components, such as the Microsoft .NET Framework or Windows XP SP2, tokens are added to the user-agent string. This is done by adding tokens to the following registry keys.
-
HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
- Token = Value
- Token = Value
-
SOFTWARE
-
Microsoft
-
Windows
-
CurrentVersion
-
Internet Settings
-
User Agent
-
Pre Platform
-
Post Platform
The Pre-Platform and Post-Platform keys contain values whose names appear before and after the Platform token respectively. For example, if a string value is added to the Post-platform key, the name appears after platform token in the user-agent string. Multiple tokens added to either key appear in an unpredictable order.
You can also override certain tokens of the user-agent string by adding values to the following registry key
-
HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
- (default) = "Mozilla/4.0"
- Compatible = "compatible"
- Platform = "Windows NT 5.1"
- Version = "MSIE 6.0"
- Token = Value
- Token = Value
-
SOFTWARE
-
Microsoft
-
Windows
-
CurrentVersion
-
Internet Settings
-
5.0
-
User Agent
-
Pre Platform
-
Post Platform
The default value of the User-agent key replaces the application name and application version tokens reported in the user-agent string. Note that the first seven characters are used for the application name and the remaining characters specify the application version token.
The Compatible, Platform, and Version values replace the corresponding tokens in the user-agent string.
Additional tokens can be added to the user-agent string by using the Registry Editor to create new string values under the Pre Platform or Post Platform keys. The value's name should be the complete token; the value's data is ignored. Tokens added to the Pre Platform key appear before the platform token in the final user-agent string. Tokens added to the Post Platform key appear after the platform token in the final user-agent string. Multiple tokens in either the Pre Platform or Post Platform keys are displayed in an unpredictable order.