Home

ASP ADVANCED

One explanation for the explosive growth of the Internet is the openness of its standards.  HTML was designed to be platform - and browser-neutral.  In theory, a Web page should appear the same way regardless of the browser and the computer being used.  In reality, however, this was never quite true.  From the beginning, Netscape introduced proprietary HTML tags.  For example, Netscape Navigator version 1.0 could interpret an HTML tag for blinking text.  To this day, the majority of non-Netscape browsers can't interpret this tag.  Frames are another example of a Netscape extension to HTML.

As competition between Netscape and Microsoft has heated up, the situation has only worsened.  Microsoft has introduced its fair share of proprietary tags.  For example, the <BGSOUND> tag, which plays background sounds, and the <MARQUEE> tag, which displays a scrolling marquee, can be interpreted only by the Microsoft browser.

HTML is being fragmented steadily into multiple standards.  With each new version of the Microsoft and Netscape browsers, the gap between what might be called "Netscape HTML" and "Microsoft HTML" widens.  This creates a serious problem for the Web page designer.

On the one hand, there's pressure on the Web page designer to include the newest HTML tags.  Never underestimate the "coolness factor." If you want users to return to your Web site, you need to push the limits of HTML.

On the other hand, there's pressure on the Web page designer to make Web pages universally accessible.  No one appreciates a Web page that they can't see.  As soon as you use proprietary HTML tags, you risk losing whole populations of potential users.

Caught between these contradictory pressures, what should a good Web page designer do?  Microsoft's answer is to use the Browser Capabilities component, as described in the following section.

Using the Browser Capabilities Component

You can use the Browser Capabilities component to display different Web pages, depending on the capabilities of a browser.  For example, some browsers support frames; others don't.  Using the Browser Capabilities component, you can detect whether a browser supports frames, and display a framed version of a page only when appropriate. 

By default, the Browser Capabilities component can detect the following features of a Web browser:

  • browser. The type of the browser; for example, Internet Explorer or Netscape.
  • version. The complete version of the browser.
  • majorver. The major version of the browser (the number before the period).
  • minorver. The minor version of the browser (the number after the period).
  • frames. Indicates whether the browser supports frames.
  • tables. Indicates whether the browser supports tables.
  • cookies. Indicates whether the browser supports cookies.
  • backgroundsounds. Indicates whether the browser supports the <BGSOUND> tag.
  • vbscript. Indicates whether the browser supports client-side VBScript scripts.
  • javascript. Indicates whether the browser supports client-side JavaScript scripts.
  • javaapplets. Indicates whether the browser supports Java applets.
  • ActiveXControls. Indicates whether the browser supports client-side ActiveX controls.
  • beta. Indicates whether the browser is still a beta version.
  • platform. Indicates the operating system of the browser.  For example, Windows 95, Windows NT, or Mac PowerPC.
  • win16. Indicates whether the browser runs on Windows 3.x rather than Windows 95 or Windows NT.

To use the Browser Capabilities component, you need to create an instance of it.  Next, you can simply append the feature you want to detect to the name of the component instance.  Here's an example that displays a number of browser features:

<HTML>
<HEAD><TITLE> Browser Capabilities Example </TITLE></HEAD>
<BODY>
<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>

Your browser has the following properties:
<P>
<TABLE BORDER=1 CELLPADDING=10>
<TR>
<TD>Browser Type</TD><TD><%=MyBrow.Browser%></TD>
</TR>
<TR>
<TD>Cookies</TD><TD><%=MyBrow.Cookies%></TD>
</TR>
<TR>
<TD>Frames</TD><TD><%=MyBrow.Frames%></TD>
</TR>
<TR>
<TD>Platform</TD><TD><%=MyBrow.Platform%></TD>
</TR>
<TR>
<TD>VBScript</TD><TD><%=MyBrow.vbscript%></TD>
</TR>
</TABLE>
</BODY>
</HTML>

This script detects and displays a number of browser features.  For different browsers, different results will be displayed.

How the Browser Capabilities Component Really Works

It's important to understand how the Browser Capabilities component really works so you can understand some of its serious limitations.  The component detects the features of a browser by using an HTML request header and a special text file that contains browser information.

Whenever a browser makes a request, it includes a USER -AGENT header in the request.  This header contains information about the type of browser being used and its version number.  You can retrieve this header directly by using the ServerVariables collection of the Request object, like this:

<%=Request.ServerVariables("HTTP_USER_AGENT")%>

When used with Netscape Navigator 3.0, for instance, the value of the USER -AGENT header would be as follows:

Mozilla/3.0 (WinNT; I)

It's important to understand that this is the only information passed between the browser and the server.  The Browser Capabilities component depends on the information in this header.  The component doesn't detect any of the features of a browser directly.

The Browser Capabilities component retrieves the value of the USER -AGENT header and attempts to match it with a browser definition in a special file named browscap.ini.  The browscap.ini file is located on the server.  When you installed Active Server Pages, this file was automatically installed as well.

The browscap.ini file is nothing more than a normal text file.  It contains a list of browsers and their features.  For example, this is the browser definition in the browscap.ini file for Netscape Navigator version 2.0.

[Netscape 2.0]
browser=Netscape
version=2.0
majorver=2
minorver=0
frames=TRUE
tables=TRUE
cookies=TRUE
backgroundsounds=FALSE
vbscript=FALSE
javascript=TRUE
javaapplets=TRUE
beta=False
Winl6=False

The Browser Capabilities component uses this definition when it reports the features of Netscape Navigator 2.0. You can modify this text file directly.  For example, contrary to reality, you could specify that Netscape Navigator 2.0 can use the <BGSOUND> tag by changing backgroundsounds from FALSE to TRUE.

There are a number of browser features that the Browser Capabilities component should detect but doesn't.  For example, it would be extremely useful if you could use the component to detect whether a certain browser can use the Secure Sockets Layer or cascading style sheets.  Because this information isn't included in the browscap.ini file, however, you can't use the Browser Capabilities component to detect these features.  However, you can add this information to the browscap.ini file yourself.  For example, you can add the following two lines to the definition entry for Netscape Navigator 2.0:

SSL=TRUE
CSS=FALSE

Once these two lines are added, the Browser Component will report these features for Netscape Navigator 2.0. Whenever the component detects that a browser is Netscape Navigator 2.0 (using the USER - AGENT header); the component will assume that the browser has these properties.  For example, the following script returns TRUE when included in a page retrieved by Netscape Navigator 2.0:

<%=MyBrow.SSL %>

You might notice that many of the browser definitions in the browscap.ini file look like this:

[Mozilla/2.0 (Win95; U)]
parent=Netscape 2.0
platform=Win95

When a browser definition has a parent parameter, the definition will inherit all the features of its parent.  The preceding definition inherits all the features of the Netscape Navigator 2.0 browser.  For instance, even though the definition doesn't specify whether the Windows 95 version of Netscape can use frames, the Browser Capabilities component will report that this version of Netscape Navigator can use frames because its parent can.

With the parent parameter, the same information doesn't have to be entered over and over.  You can make one parent definition, and create a number of smaller child definitions that contain more specific information.  Any browser feature specified in the child definition that conflicts with the parent definition will take precedence.

The Browser Capabilities component is only as accurate as the browscap.ini file. If someone is using a browser or a version of a browser that isn't included in the browscap.ini file, the Browser

Capabilities component won't be able to report its features accurately. When the Browser Capabilities component doesn't recognize a browser, it reports the features specified for the default browser.  This is an example of the default browser definition:

[Default Browser Capability Settings]
browser=Default
Version=0.0
majorver=#0
minorver=#0
frames=False
tables=True
cookies=False
backgroundsounds=False
vbscript=False
javascript=False
javaapplets=False
activexcontrols=False
AK=False
SK=False
AOL=False
beta=False
Win16=False
Crawler=False
CDF=False

Again, if you don't like the default properties specified in the browscap.ini file, you can modify them directly.  For example, you might not want to assume that all browsers can use tables.  To change this assumption, simply change the value of the tables property in the definition for the default browser.