Library code snippets

Visitors' Browser Information

The information that is available to client-side scripts (ie JavaScript) regarding browser version, operating system etc. is also made available to ASP scripts. For example, to get the visitor's browser, you can use

Response.Write Request.ServerVariables("HTTP_USER_AGENT")

Below are some examples of the values that can be returned:

'Windows NT 4, IE 6
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)

'Windows 2000, IE 5.01
Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)

'Netscape 6.1, Windows 98
Mozilla/5.0 (windows; u; windows 98; en-us; rv:0.9.2) gecko/20010726 netscape6/6.1

'Opera, Windows 95
Mozilla/5.0 (windows 95; u) opera 5.01 [en]

Obviously, to determine the user's browser using code is not particularly straight forward. Obviously, you can check if it is IE by using

If InStr(1, Request.ServerVariables("HTTP_USER_AGENT"),"MSIE") Then
    'is Microsoft Internet Explorer
End If

However, retrieving any more detailed information is very difficult. Fortunately, Microsoft have the answer (!), with their Browser Capabilities component. This component reveals not only what make of browser it is, but whether it supports frames, vb script etc. Below is a simple example

<%
'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>

Having said that, it can't be entirely relied upon; it identifies my copy of IE 6 as Netscape 4.0! (The Browser Capabilities component gets its information from c:\winnt\system32\inetsrv\browscap.ini)

Comments

  1. 23 May 2002 at 14:37

    I've found browscap.ini updates for IE on MSDN.  Does Netscape release anything to help us update our own ini files?  Cyscapes version is outdated (obviously).

  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Visitors' Browser Information.

Leave a comment

Sign in or Join us (it's free).

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

We'd love to hear what you think! Submit ideas or give us feedback