

ASP ADVANCED
A Sample Application
of the Browser Capabilities Component
This section presents a
possible application of the Browser Capabilities component.
The purpose of this example is not only to show how to use the
component, but also to show its limitations.
In the Active Server
Page shown in Listing 18.1, the Browser Capabilities component is used to
detect whether a browser can use frames.
If the browser can use frames, a framed version of
the page is displayed. If the
browser can't use frames, the user is warned that he or she must have a
frames-compliant browser to visit the Web site.
<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
IF MyBrow.Frames THEN
%>
<HTML>
<HEAD><TITLE> Framed Page </TITLE></HEAD>
<FRAMESET COLS="100,*">
<FRAME SRC="menu.asp">
<FRAME SRC="body.asp">
</FRAMESET>
</HTML>
<% ELSE %>
<HTML>
<HEAD><TITLE> Frameless Page </TITLE></HEAD>
<BODY>
We have detected that your
browser is incapable of using frames.
You are using a <%=MyBrow.browser%> browser (version <%=MyBrow.version
%>).
To download a more recent browser, please visit:
<P> <A HREF="http://www.microsoft.com">Microsoft</A>
<P> OR
<P> <A HREF="http://www.netscape.com">Netscape</A>
</BODY>
</HTML>
<% END IF %>
This Active Server
Page conditionally displays two other pages.
If the Browser Capabilities
component detects that a user's browser can interpret the frame tags, the
first page is displayed.
This page displays two frames. Otherwise,
the second page is displayed. Notice
how the Browser Capabilities component is also used to report the name and
version of the browser being used.
This example not only
illustrates how the Browser Capabilities component can be used, but also
why the component normally should not be used for this purpose.
It illustrates a serious problem with the Browser Capabilities
component.
The problem with this
Active Server Page is that it will always display the second page when it
doesn't recognize a browser. In
other words, even if a browser can support frames, the second page will be
displayed when the Browser Capabilities component doesn't recognize it.
For example, as of the printing date of this book, the current
version of the browscap.ini file didn't recognize the newest version of
the Netscape browser. Therefore,
even though this browser can use frames, the second page is displayed.
The major shortcoming of
the Browser Capabilities component is that it must depend on the
information placed by Microsoft or you in the browscap.ini file.
The speed at which new technologies and new browsers are introduced
on the Internet undermines its usefulness.
When
possible, it's much better to use HTML itself to display different
content, depending on the capabilities of a browser.
For example, a better way to detect whether a browser can use
frames is by using the <NOFRAMES> HTML tag, as described in Chapter
7, "Advanced HTML" The advantage of this approach is that it
should continue to work with new browsers.
Summary
In
this chapter, you learned how to integrate ActiveX components into your
Active Server Pages. You
learned how to create an instance of a component with page, session, and
application scope, and how to use the Browser Capabilities component.
Finally, an example of an Active Server Page using the Browser
Capabilities component was provided.
This example also demonstrated a significant limitation of this
component.
|