SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Backend Browser Detection
By Scott Isaacs

In our Fixing the Backend article we introduced our plans to rearchitect the backend to use adaptive templates to generate each page. The most important aspect in creating our adaptive backend is to have robust browser detection.

When we discuss client side browser detection, we always talk about two techniques: version and capabilities detection. Version detection just parses the user agent (UA) string of the browser, while capabilities actually interrogates the object model to check what the browser supports. In IIS there is a built-in ActiveX component that provides very similar capabilities - the browser capabilities component.

This object associates the client's UA string with a list of capabilities. Since on the server there is no way to test a client for different capabilities, the browser detection component maps the UA string to a table of capabilities. This table contains information about the client's level of HTML and scripting support.

The set of capabilities that can be tested for are defined by a special .ini file on your server. This .ini file can be updated with new capabilities files as new browsers are released, or you personally can modify the file to associate additional capabilities with each browser. This allows you to decide how and what you want to detect.

In this article we present both VBScript and JavaScript code. The default language used by your ASP pages is determined by a registry setting in IIS (standard installation defaults to VBScript). In any of your pages, you can explicitly set the language by placing a server side directive as the first script in your document. This setting has no effect on any client-side script. If you author JavaScript on your server and you do not change IIS's default settings, you must remember to change the language at the top of the page. Below we set the language for the server-side script to JavaScript.

<%@ LANGUAGE=JScript %>

Next, we introduce how to use the browser detection component.