0% found this document useful (0 votes)
35 views

User-Agent String and Version Vector

Uploaded by

luis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

User-Agent String and Version Vector

Uploaded by

luis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

User-Agent String and Version Vector:

Windows® Internet Explorer® 8


Beta 1 for Developers

Making the Web Work for You

March 2008

For more information, press only:


Rapid Response Team
Waggener Edstrom Worldwide
(503) 443-7070
[email protected]
The information contained in this document represents the current view of Microsoft Corp. on the issues discussed
as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be
interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any
information presented after the date of publication.

This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR
STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT.

Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under
copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or
transmitted in any form or by any means (electronic, mechanical, photocopying, recording or otherwise), or for
any purpose, without the express written permission of Microsoft Corp.

Microsoft may have patents, patent applications, trademarks, copyrights or other intellectual property rights
covering subject matter in this document. Except as expressly provided in any written license agreement from
Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights
or other intellectual property.

Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos,
people, places and events depicted herein are fictitious, and no association with any real company, organization,
product, domain name, email address, logo, person, place or event is intended or should be inferred.

© 2008 Microsoft Corp. All rights reserved.

Microsoft, Windows, Windows Vista, Windows Server, ActiveX, Active Directory, Internet Explorer, the Internet Explorer logo, MSN and the
MSN logo are either registered trademarks or trademarks of Microsoft Corp. in the United States and/or other countries.
The names of actual companies and products mentioned herein may be the trademarks of their respective owners.
OVERVIEW

The User-Agent string is a browser's identity as reported to Web sites via HTTP traffic; the version vector
is a mechanism for obtaining the Internet Explorer version number used to evaluate conditional
comments. Both have the potential to impact site compatibility. Understanding the best practices for
browser detection ensures that your site continues to operate as intended when viewed by Windows
Internet Explorer 8 clients.

Feature Details

User-Agent String
When you visit a Web page, your browser sends the User-Agent string to the server that hosts the
content. This string indicates which browser you are using, its version number, and details about your
system such as operating-system version. The Web server can use this information to provide content
that is tailored to your specific browser. Additionally, Internet Explorer exposes the User-Agent string as
part of the DOM, which allows code (such as script) running on the client to obtain the browser version
details.

Internet Explorer 8 Beta 1 for Developers ships with an updated User-Agent string. (The updated string is
underlined for illustration purposes only.)

Example: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)

The upside of this approach is that it is possible to differentiate Internet Explorer 8 from previous
Internet Explorer releases. The downside of this approach is that existing sites that perform exact string
matching to determine browser version will need to be updated to support Internet Explorer 8.

Best Practices:
 Review the sample code for User-Agent checking on MSDN: http://msdn2.microsoft.com/en-
us/library/ms537509.aspx.
 Review User-Agent checking code on your Web site.
o If your goal is to ensure that Internet Explorer 8 clients receive content built and tested
for Internet Explorer 7, use a greater-than-or-equal-to (>=) comparison rather than an
equal-to (=) comparison. Additionally, ensure that the document mode (such as quirks
or strict) is compatible with Internet Explorer 8.
Example:
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}
function checkVersion()
{
var msg = "You're not using Internet Explorer.";
var ver = getInternetExplorerVersion();

if ( ver > -1 )
{
if ( ver >= 7.0 )
msg = "You're using Internet Explorer 7 or Internet Explorer 8. I should send a
quirks or strict mode document."
else
msg = "You should upgrade your copy of Internet Explorer.";
}
alert( msg );
}

o If you want to target content exclusively to Internet Explorer 8—such as by sending a


document in the latest rendering mode that follows CSS 2.1 guidelines—use a greater-
than-or-equal-to (>=) comparison. An exact string match is not recommended because it
is not "future proof." In other words, if there is an Internet Explorer 9, you will need to
update your Web site at some future date to handle detecting that release.

Example:

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}
function checkVersion()
{
var msg = "You're not using Internet Explorer.";
var ver = getInternetExplorerVersion();

if ( ver > -1 )
{
if ( ver >= 8.0 )
msg = "You're using Internet Explorer 8 or later. I should send you CSS 2.1
content."
else
msg = "You should upgrade your copy of Internet Explorer.";
}
alert( msg );
}

Version Vector
Version vector is the internal version number of Internet Explorer and is stored in a registry key
read on browser start-up. Internet Explorer uses the value when processing conditional
comments, which are blocks of comments in the HTML source of a page interpreted only by
Internet Explorer. The comments can contain one or more operations, features, or values. A
common use of conditional comments involves targeting different Cascading Style Sheets (CSS)
rules for specific versions of Internet Explorer.

Internet Explorer 8 Beta 1 for Developers ships with an updated Version Vector of ‘8.0’. By
default, Internet Explorer 8 Beta 1 for Developers will attempt to render documents by using its
most standards-compliant mode (except documents with a “Quirks” DOCTYPE declaration).
Therefore, in order to ensure site compatibility with existing Web content, you must author
conditional comments such that Internet Explorer 8 clients do not receive non-standard CSS fix-
ups and changes. See the following table for examples.

Intended Outcome Sample Syntax


Ensure Internet Explorer 8 receives the same <--[if gte IE 7]>
conditional comment block as Internet
Explorer 7. You should only use this option if
sending a Quirks mode or IE7 standards mode
document.
Target Internet Explorer 8 only <--[if gte IE 8]>
Target Internet Explorer 7 only <--[if IE 7]>

Best Practices:
 Review the sample code for using conditional comments on MSDN.
(http://msdn2.microsoft.com/en-us/library/ms537509.aspx)
 Review conditional comments used on your Web site.
o If your goal is to ensure Internet Explorer 8 clients receive content built and tested for
Internet Explorer 7, you must examine existing content to ensure the comment block
evaluates to TRUE for Internet Explorer 8 clients.

Example:
<head>
<title>Test Page</title>
<!--[if gte IE 7]>
<link rel="stylesheet" type="text/css" href="/stylesheets/ie.css" />
<p>Both Internet Explorer 8 and Internet Explorer 7 will receive this style sheet.
</p>
<![endif]-->
</style>
</head>
o If your goal is to target Internet Explorer 8 clients and Internet Explorer 7 clients
separately, you should use two conditional comment blocks. First, use a greater than or
equal to (>=) comparison for the Internet Explorer 8 comment block. NOTE: Using an
exact string match is not recommended because it is not “future proof.” In other words,
assuming there were an Internet Explorer 9, you would need to update your Web site at
some future date to handle detecting that release. Second, use an equal to (=)
comparison for the Internet Explorer 7 comment block.

Example:
<head>
<title>Test Page</title>
<meta http-equiv="X-UA-Compatible" content="IE=8" >
<!--[if gte IE 8]>
<link rel="stylesheet" type="text/css" href="/stylesheets/standards.css" />
<p>Internet Explorer 8 and greater will receive this style sheet. </p>
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="/stylesheets/ie.css" />
<p>Internet Explorer 7 will receive this style sheet.</p>
<![endif]-->
</style>
</head>

You might also like