Microsoft KB Archive/224979

= Using Browser Capabilities with Internet Explorer 5.0 Client Capabilities =

Article ID: 224979

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q224979



SUMMARY
Microsoft Internet Information Services (IIS) version 5.0 with Active Server Pages (ASP) and Internet Explorer provides enhanced client and server capabilities components that can be combined to allow Web developers greater control over the presentation of Web data to clients.

This article explains how to combine these new features in a working example scenario.



MORE INFORMATION
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Client Capabilities in Internet Explorer
Microsoft Internet Explorer 4.0 introduced several client-side attributes to the DHTML Object Model (DOM) that can be used in customizing a page layout after it has been rendered for the client. Internet Explorer 5.0 takes this a step further by exposing this information as one of the browser's Default Behaviors.

The following table is a partial list of useful client capabilities. (For a more complete list see the MSDN clientCaps Behavior page.)

Browser Capabilities in IIS
IIS 5.0 adds server-side functionality by exchanging the client capabilities information through cookies and returning this information to an ASP page as part of the Browser Capabilities component. This allows Web developers that ability to write ASP code that is custom tailored for a client's display.

Implementation
Combining the Internet Explorer 5.0 and IIS 5.0 functionality into a single implementation can be thought of as a two-step process:

 A DHTML page needs to be created to obtain the client capabilities and store them in cookies.

  The DHTML page needs to declare the clientcaps behavior.

   IE\:clientCaps {behavior:url(#default#clientcaps)} 

     All desired capabilities need to collected as name=value pairs.</li> All name=value pairs need to be concatenated together into a single string separated by ampersands (&).</li> The resulting string needs to be stored in a cookie named BrowsCap.</li>  The following example page illustrates all of the above steps. Copy this code and save it is "clientcap.htm" on your IIS computer in a Web folder with Script and Read access enabled.

<HTML XMLNS:IE> 

 IE\:clientCaps {behavior:url(#default#clientcaps)} </STYLE>

<SCRIPT language="JavaScript">

function stopAllErrors { return true; }

window.onerror = stopAllErrors;

function window.onload { var strBrowsCap;

strBrowsCap = "availHeight="     + objClientCaps.availHeight; strBrowsCap += "&availWidth="    + objClientCaps.availWidth; strBrowsCap += "&bufferDepth="   + objClientCaps.bufferDepth; strBrowsCap += "&colorDepth="    + objClientCaps.colorDepth; strBrowsCap += "&cookieEnabled=" + objClientCaps.cookieEnabled; strBrowsCap += "&cpuClass="      + objClientCaps.cpuClass; strBrowsCap += "&height="        + objClientCaps.height; strBrowsCap += "&javaEnabled="   + objClientCaps.javaEnabled; strBrowsCap += "&platform="      + objClientCaps.platform; strBrowsCap += "&systemLanguage=" + objClientCaps.systemLanguage; strBrowsCap += "&userLanguage="  + objClientCaps.userLanguage; strBrowsCap += "&width="         + objClientCaps.width;

document.cookie = "BrowsCap=" + strBrowsCap; } </SCRIPT> </HEAD>

 <IE:clientcaps ID="objClientCaps" /> </BODY> <HTML> </li></ol> </li> An ASP page needs to be created to read and use this information. <ol style="list-style-type: lower-alpha;">  The ASP page needs to reference the DHTML client capabilities through the use of a special METADATA tag:

Note:The SRC attribute of the tag needs to be set to the name of your DHTML page. </li>  Next, a BrowserType component needs to be created in the ASP page: <% Set objBrowserType = Server.CreateObject("MSWC.BrowserType") %> </li>  Individual client attributes can now be obtained by referencing them by name: <P>availHeight = <%=objBrowserType.availHeight%></P> <P>availWidth = <%=objBrowserType.availWidth%></P> </li>  The following example page illustrates all of the above steps. Copy this code and save it is "Clientcap.asp" on your IIS computer in the same Web folder as "Clientcap.htm."

<%@LANGUAGE="VBSCRIPT"%> <HTML>  <TITLE>Client Capabilities Test</TITLE> </HEAD> 

<H2 ALIGN="CENTER">Client Capabilities Test</H2> <CENTER> <% Set objBrowserType = Server.CreateObject("MSWC.BrowserType") %> </CENTER> </BODY> </HTML> </li></ol> </li></ol>

Example Scenario
The following ASP example uses the DHTML client capabilities "Clientcap.htm" page from earlier and shows some of the above properties in action. This example illustrates a splash screen style home page for a Web site by:


 * 1) Creating a table at 90% width and 50% height of the available screen.Creating the page title based on the user's CPU type and operating platform.Creating a URL to another Web folder from the user's language setting.
 * 2) Creating the page title based on the user's CPU type and operating platform.Creating a URL to another Web folder from the user's language setting.
 * 3) Creating a URL to another Web folder from the user's language setting.

<%@LANGUAGE="VBSCRIPT"%> <HTML>  <TITLE>Welcome to our Web Site!</TITLE> </HEAD> <BODY BGCOLOR="#000000">

<H2 ALIGN="CENTER">Client Capabilities Test</H2> <CENTER> <% Set objBrowserType = Server.CreateObject("MSWC.BrowserType") %> </CENTER> </BODY> </HTML> For more information, please see the Microsoft Scripting Technologies Web site.

Keywords: kbhowto KB224979

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.