Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 18,350 times

Related Categories

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)

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • cyscape dropping the ball

    Posted by ecunningham on 23 May 2002

    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).