DOCUMENT:Q224979 20-JUL-2001 [iis] TITLE :Using Browser Capabilities with Internet Explorer 5.0 PRODUCT :Internet Information Server PROD/VER:WINDOWS:5; winnt:5.0 OPER/SYS: KEYWORDS: ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Internet Information Services version 5.0 - Microsoft Internet Explorer version 5 for Windows NT 4.0 ------------------------------------------------------------------------------- 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.) +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Client Capability | Description | DHTML Implementation | +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | AvailHeight | Specifies the height of the working area of the system's screen, in pixels, excluding the taskbar. | Window.screen.availHeight | +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | AvailWidth | Specifies the width of the working area of the system's screen, in pixels, excluding the taskbar. | Window.screen.availWidth | +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | BufferDepth | Specifies the number of bits per pixel used for colors on the off- screen bitmap buffer. | Window.screen.bufferDepth | +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | ColorDepth | Specifies the number of bits per pixel used for colors on the destination device or buffer. | Window.screen.colorDepth | +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | CookieEnabled | Specifies whether client-side cookies are enabled in the browser. | Window.navigator.cookieEnabled | +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | CpuClass | Specifies the type of CPU of the client computer. | Window.navigator.cpuClass | +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Height | Specifies the vertical resolution of the screen, in pixels. | Window.screen.height | +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | JavaEnabled | Specifies whether the Microsoft virtual computer is enabled in the browser. | Window.navigator.javaEnabled() | +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Platform | Specifies the platform on which the browser is running. | Window.navigator.platform | +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | SystemLanguage | Specifies the default language that the system is running. | Window.navigator.systemLanguage | +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | UserLanguage | Indicates the current user language. | Window.navigator.userLanguage | +----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Width | Specifies 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 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: 1. A DHTML page needs to be created to obtain the client capabilities and store them in cookies. a. The DHTML page needs to declare the clientcaps behavior. b. All desired capabilities need to collected as name=value pairs. c. All name=value pairs need to be concatenated together into a single string separated by ampersands (&). d. The resulting string needs to be stored in a cookie named BrowsCap. e. 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. 2. An ASP page needs to be created to read and use this information. a. 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. b. Next, a BrowserType component needs to be created in the ASP page: <% Set objBrowserType = Server.CreateObject("MSWC.BrowserType") %> c. Individual client attributes can now be obtained by referencing them by name:

availHeight = <%=objBrowserType.availHeight%>

availWidth = <%=objBrowserType.availWidth%>

d. 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"%> Client Capabilities Test

Client Capabilities Test

<% Set objBrowserType = Server.CreateObject("MSWC.BrowserType") %>
Attribute Value
availHeight <%=objBrowserType.availHeight %>
availWidth <%=objBrowserType.availWidth %>
bufferDepth <%=objBrowserType.bufferDepth %>
colorDepth <%=objBrowserType.colorDepth %>
cookieEnabled <%=objBrowserType.cookieEnabled %>
cpuClass <%=objBrowserType.cpuClass %>
height <%=objBrowserType.height %>
javaEnabled <%=objBrowserType.javaEnabled %>
platform <%=objBrowserType.platform %>
systemLanguage<%=objBrowserType.systemLanguage%>
userLanguage <%=objBrowserType.userLanguage %>
width <%=objBrowserType.width %>
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. 2. Creating the page title based on the user's CPU type and operating platform. 3. Creating a URL to another Web folder from the user's language setting. <%@LANGUAGE="VBSCRIPT"%> Welcome to our Web Site!

Client Capabilities Test

<% Set objBrowserType = Server.CreateObject("MSWC.BrowserType") %>

Welcome to the <%=UCase(objBrowserType.cpuClass)%> site!

This site is dedicated to <%=UCase(objBrowserType.platform)%> issues.

Click Here to Continue

For more information, please see the Microsoft Scripting Technologies Web site. Additional query words: ====================================================================== Keywords : Technology : kbiisSearch kbIEsearch kbiis500 kbZNotKeyword2 kbIENT400Search kbIE500Search kbZNotKeyword3 kbIE500WinNT400 Version : WINDOWS:5; winnt:5.0 Issue type : kbhowto ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2001.