When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
Print this page.
Published: Thursday, December 14, 2000

Obtaining your User's Browser Information

  • Read Part 1

  • In Part 1 we looked at how to use client-side scripting techniques and the User-Agent server variable to determine the user's browser type and version. In this part we will look at using two more server-side techniques: using Microsoft's Browser Capabilities component, and using a BrowserHawk, a commercial, third-party component.

    - continued -

    Using Microsoft's Browser Capabilities
    Microsoft provides a free component (and file) with IIS 4 and IIS 5 called Browser Capabilities. This component maps the visitor's User-Agent string to an entry in a file BrowsCap.ini (it's located in the \WinNT\system32\inetsrv directory on my computer). Under each listing of browser type in the file are a number of properties, indiciating whether or not a specific browser and version supports a specific property. This file, then, can be accessed programmatically through the Browser Capabilities component. For example, to list the browser name and version, along with whether that browser can support frames, you could use code like:

      'Create an instance of the Browser Capabilities Component
      Dim objBC
      Set objBC = Server.CreateObject("MSWC.BrowserType")
    <b>Your browser:</b> <%=objBC.Browser%><br>
    <b>Browser version:</b> <%=objBC.Version%><br>
    <b>Support Frames?</B> <%=objBC.Frames%><br>

    The output of the above script, for your browser, can be seen below:
    Your browser: Default
    Browser version: 0.0
    Support Frames? False

    For another Browser Capabilities example, be sure to view our live demo.

    Since the Browser Capabilities component determines a browser's properties through this file, it is important that this file be updated when new browsers hit the market (such as Opera, or new version of IE or Netscape). You can learn where to download the latest version of browscap.ini at this Microsoft article. Also, for a more intricate Browser Capabilities code example, be sure to check out: Browser Capabilities Code Sample.

    Using BrowserHawk to Perform Browser Detection
    All of the solutions we've examine thus far provide just a few minimal bits of information about the user's Web browser. The Browser Capabilities component has been the most in-depth thus far, providing information on whether or not the browser has the ability to support frames, cookies, JavaScript, and other features that earlier browsers may not have supported. (Note that the Browser Capabilities Component just tells you whether or not the browser can support these features; since IE 5.0 has JavaScript support, the Browser Capabilities component will indicate that a user who is visiting with IE 5.0 has JavaScript capabilities, regardless if they user has setup his browser to have client-side JavaScripting disabled.)

    BrowserHawk, a browser detection component put out by the people at cyScape, is a commercial, third-party component that excels in browser and browser capabilities detection. With BrowserHawk, you can determine a whole slew of things, such as whether or not the user has: cookies enabled, JavaScript enabled, Java Applet support enabled, if they're using an AOL browser, if they can support SSL connections, if they support PNG image display, if they have various plug-ins (such as Acrobat Reader, QuickTime, Flash, etc.), if they support XML display, if the browser supports HDML or WML, etc.

    The only downside to BrowserHawk is that it is not a free component. You can download a free version to play around with it and see if it meets your needs, but, to keep it from expiring, you'll eventually need to buy a copy, which can run from $119 to $489, depending on the version you're interested in.

    For some great demos with BrowserHawk, be sure to read the following articles:

    Well, that about wraps this article up! We've examined four different ways to perform browser detection. When it comes to browser detection and capabilities there's a trade-off between fast and free with few features and slower and more costly with many more features. Your choice should depend on what needs you have and what types of browser capabilities you need to be able to detect.

    Happy Programming!

    ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article