Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP Browser Capabilities

ASP Browser Capabilities component


ASP Browser Capabilities component

The ASP Browser Capabilities component creates a BrowserType object that can determine the type, capabilities, and version number of a visitor's browser.

When a browser connects to the server, it sends an HTTP User Agent header to the server. This header contains information about the browser.

The BrowserType object compares the information in the header with information in a file on the server named "Browscap.ini".

If the browser type and version number in the header match the information in the "Browsercap.ini" file, we can use the BrowserType object to list the relevant properties of the matching browser. If there is no match, the object sets each property to "UNKNOWN".

Syntax

<%

Set MyBrow=Server.CreateObject("MSWC.BrowserType")

%>


ASP Browser Capabilities example

The example below creates a BrowserType object in an ASP file and displays some information about the current browser's capabilities:

Example

<%

Set MyBrow=Server.CreateObject("MSWC.BrowserType")

%>

Client OS <%=MyBrow.platform%>
Web Browser <%=MyBrow.browser%>
Browser version <%=MyBrow.version%>
Frame support? <%=MyBrow.frames%>
Table support? <%=MyBrow.tables%>
Sound support? <%=MyBrow.backgroundsounds%>
Cookies support? <%=MyBrow.cookies%>
VBScript support? <%=MyBrow.vbscript%>
JavaScript support? <%=MyBrow.javascript%>

Output:

Client OS WinNT
Web Browser IE
Browser version 5.0
Frame support? True
Table support? True
Sound support? True
Cookies support? True
VBScript support? True
JavaScript support? True

Demo Example »


Browscap.ini file

The "Browscap.ini" file is used to declare properties and set default values for each browser.

This section is not a to-do on how to maintain the Browscap.ini file; we only provide some basic knowledge and concepts about "Browsercap.ini" to give you a general understanding of the file.

The "Browscap.ini" file can contain the following information:

[;comments]

[HTTPUserAgentHeader]

[parent=browserDefinition]

[property1=value1]

[propertyN=valueN]

[Default Browser Capability Settings]

[defaultProperty1=defaultValue1]

[defaultPropertyN=defaultValueN]

Parameters Description
comments Optional. Any line of code beginning with a semicolon is ignored by the BrowserType object.
HTTPUserAgentHeader Optional. Specifies the HTTP User Agent header associated with the declaration of the browser-property value set in propertyN. Wildcards are allowed.
browserDefinition Optional. Specifies the HTTP User Agent header-string of a browser to be used as the parent browser. The definition of the current browser inherits all declared property values from the parent browser's definition.
propertyN Optional. Specifies the properties of a browser. The table below lists some possible properties:
  • ActiveXControls - Supports ActiveX® controls?
  • Backgroundsounds - Supports background sounds?
  • Cdf - Supports the Channel Definition Format for webcasting?
  • Tables - Support tables?
  • Cookies - Support cookies?
  • Frames - Support frames?
  • Javaapplets - Support Java applets?
  • Javascript - Support JScript?
  • Vbscript - Support VBScript?
  • Browser - Specifies the name of the browser
  • Beta - Is the browser beta software?
  • Platform - Specifies the platform the browser runs on
  • Version - Specifies the browser's version number
  • | | valueN | Optional. Specifies the value of propertyN. Can be a string, an integer (prefixed with #), or a Boolean value. | | defaultPropertyN | Optional. Specifies the name of a browser property. If none of the defined HTTPUserAgentHeader values match the HTTP User Agent header sent by the browser, a default value is assigned to this property. | | defaultValueN | Optional. Specifies the value of defaultPropertyN. Can be a string, an integer (prefixed with #), or a Boolean value. |

    The "Browscap.ini" file might look like this:

    ;IE 5.0

    [IE 5.0]

    browser=IE

    Version=5.0

    majorver=#5

    minorver=#0

    frames=TRUE

    tables=TRUE

    cookies=TRUE

    backgroundsounds=TRUE

    vbscript=TRUE

    javascript=TRUE

    javaapplets=TRUE

    ActiveXControls=TRUE

    beta=False

    ;DEFAULT BROWSER

    [*]

    browser=Default

    frames=FALSE

    tables=TRUE

    cookies=FALSE

    backgroundsounds=FALSE

    vbscript=FALSE

    javascript=FALSE