Using Browser Capabilities with Internet Explorer 5.0 Client Capabilities

This article has been archived. It is offered "as is" and will no longer be updated.
Summary
Microsoft Internet Information Services (IIS) version 5.0 with ActiveServer Pages (ASP) and Internet Explorer provides enhanced client andserver capabilities components that can be combined to allow Webdevelopers greater control over the presentation of Web data toclients.

This article explains how to combine these new features in a workingexample scenario.
More information
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUROWN RISK. Microsoft provides this code "as is" without warranty of anykind, either express or implied, including but not limited to the impliedwarranties of merchantability and/or fitness for a particular purpose.

Client Capabilities in Internet Explorer

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

The following table is a partial list of useful client capabilities.
Client CapabilityDescriptionDHTML Implementation
AvailHeightSpecifies the height of the working area of the system's screen,in pixels, excluding the taskbar.Window.screen.availHeight
AvailWidthSpecifies the width of the working area of the system's screen, inpixels, excluding the taskbar.Window.screen.availWidth
BufferDepthSpecifies the number of bits per pixel used for colors on the off-screen bitmap buffer.Window.screen.bufferDepth
ColorDepthSpecifies the number of bits per pixel used for colors on thedestination device or buffer.Window.screen.colorDepth
CookieEnabledSpecifies whether client-side cookies are enabled in thebrowser.Window.navigator.cookieEnabled
CpuClassSpecifies the type of CPU of the client computer.Window.navigator.cpuClass
HeightSpecifies the vertical resolution of the screen, in pixels.Window.screen.height
JavaEnabledSpecifies whether the Microsoft virtual computer is enabled in thebrowser.Window.navigator.javaEnabled()
PlatformSpecifies the platform on which the browser is running.Window.navigator.platform
SystemLanguageSpecifies the default language that the system is running.Window.navigator.systemLanguage
UserLanguageIndicates the current user language.Window.navigator.userLanguage
WidthSpecifies the horizontal resolution of the screen, in pixels.Window.screen.width

Browser Capabilities in IIS

IIS 5.0 adds server-side functionality by exchanging the clientcapabilities information through cookies and returning this information toan ASP page as part of the Browser Capabilities component. This allowsWeb developers that ability to write ASP code that is custom tailored fora client's display.

Implementation

Combining the Internet Explorer 5.0 and IIS 5.0functionality into a single implementation can be thought of as a two-stepprocess:
  1. A DHTML page needs to be created to obtain the client capabilitiesand store them in cookies.

    1. The DHTML page needs to declare the clientcaps behavior.

      <HTML XMLNS:IE><HEAD><STYLE>  IE\:clientCaps {behavior:url(#default#clientcaps)}</STYLE><!-- client capabilities code goes here --></HEAD><BODY>  <IE:clientcaps ID="objClientCaps" /></BODY>								
    2. All desired capabilities need to collected as name=valuepairs.
    3. All name=value pairs need to be concatenated together into asingle string separated by ampersands (&).
    4. The resulting string needs to be stored in a cookie namedBrowsCap.
    5. The following example page illustrates all of the above steps. Copythis code and save it is "clientcap.htm" on your IIS computer in a Webfolder with Script and Read access enabled.

      <HTML XMLNS:IE><HEAD><STYLE>  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><BODY>  <IE:clientcaps ID="objClientCaps" /></BODY><HTML>								
  2. An ASP page needs to be created to read and use this information.
    1. The ASP page needs to reference the DHTML client capabilities throughthe use of a special METADATA tag:

      <!--METADATA TYPE="Cookie" NAME="BrowsCap" SRC="clientcap.htm"-->								


      Note:The SRC attribute of the tag needs to be set to thename of your DHTML page.
    2. Next, a BrowserType component needs to be created in the ASP page:
      <% Set objBrowserType = Server.CreateObject("MSWC.BrowserType") %>								
    3. Individual client attributes can now be obtained by referencing themby name:
      <P>availHeight = <%=objBrowserType.availHeight%></P><P>availWidth = <%=objBrowserType.availWidth%></P>								
    4. The following example page illustrates all of the above steps. Copythis code and save it is "Clientcap.asp" on your IIS computer in the sameWeb folder as "Clientcap.htm."
      <%@LANGUAGE="VBSCRIPT"%><HTML><HEAD><TITLE>Client Capabilities Test</TITLE></HEAD><BODY><!--METADATA TYPE="Cookie" NAME="BrowsCap" SRC="clientcap.htm"--><H2 ALIGN="CENTER">Client Capabilities Test</H2><CENTER><% Set objBrowserType = Server.CreateObject("MSWC.BrowserType") %><TABLE BORDER="1">  <TR><TH>Attribute     </TH><TH>Value</TH></TR>  <TR><TD>availHeight   </TD><TD><%=objBrowserType.availHeight%></TD></TR>  <TR><TD>availWidth    </TD><TD><%=objBrowserType.availWidth%></TD></TR>  <TR><TD>bufferDepth   </TD><TD><%=objBrowserType.bufferDepth%></TD></TR>  <TR><TD>colorDepth    </TD><TD><%=objBrowserType.colorDepth%></TD></TR>  <TR><TD>cookieEnabled </TD><TD><%=objBrowserType.cookieEnabled%></TD></TR>  <TR><TD>cpuClass      </TD><TD><%=objBrowserType.cpuClass%></TD></TR>  <TR><TD>height        </TD><TD><%=objBrowserType.height%></TD></TR>  <TR><TD>javaEnabled   </TD><TD><%=objBrowserType.javaEnabled%></TD></TR>  <TR><TD>platform      </TD><TD><%=objBrowserType.platform%></TD></TR><TR><TD>systemLanguage</TD><TD><%=objBrowserType.systemLanguage%></TD></TR>  <TR><TD>userLanguage  </TD><TD><%=objBrowserType.userLanguage%></TD></TR>  <TR><TD>width         </TD><TD><%=objBrowserType.width%></TD></TR></TABLE></CENTER></BODY></HTML>								

Example Scenario

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

  1. Creating a table at 90% width and 50% height of the availablescreen.Creating the page title based on the user's CPU type and operatingplatform.Creating a URL to another Web folder from the user's languagesetting.
  2. Creating the page title based on the user's CPU type and operatingplatform.Creating a URL to another Web folder from the user's languagesetting.
  3. Creating a URL to another Web folder from the user's languagesetting.
<%@LANGUAGE="VBSCRIPT"%><HTML><HEAD><TITLE>Welcome to our Web Site!</TITLE></HEAD><BODY BGCOLOR="#000000"><!--METADATA TYPE="Cookie" NAME="BrowsCap" SRC="clientcap.htm"--><H2 ALIGN="CENTER">Client Capabilities Test</H2><CENTER><% Set objBrowserType = Server.CreateObject("MSWC.BrowserType") %><TABLE WIDTH="<%=objBrowserType.availWidth * .9%>"HEIGHT="<%=objBrowserType.availHeight * .5%>">  <TR>    <TD ALIGN="CENTER" BGCOLOR="#FFFFFF">      <H2>Welcome to the <%=UCase(objBrowserType.cpuClass)%> site!</H2>      <P>This site is dedicated to <%=UCase(objBrowserType.platform)%>issues.</P>      <P><A HREF="/<%=objBrowserType.userLanguage%>/">Click Here toContinue</A></P>  </TR></TABLE></CENTER></BODY></HTML>				
For more information, please see the Microsoft ScriptingTechnologies Web site.
Properties

Article ID: 224979 - Last Review: 01/11/2015 02:34:40 - Revision: 4.0

  • kbnosurvey kbarchive kbhowto KB224979
Feedback