ASP Browser Capabilities



ASP Browser Capabilities Component

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

When the 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 the information in a file named "Browscap.ini" on the server.

If the browser type and version number in the header match the information in the "Browsercap.ini" file, then we can use the BrowserType object to list the related properties of the matching browser. If the above does not match, the object will set every property to "UNKNOWN".

Syntax

<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>


ASP Browser Capabilities Example

The following example will create a BrowserType object in the ASP file and display some information about the current browser performance:

Instance

<!DOCTYPE html>
<html>
<body>
<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>

<table border="0" width="100%">
<tr>
<th>Client OS</th><th><%=MyBrow.platform%></th>
</tr><tr>
<td >Web Browser</td><td ><%=MyBrow.browser%></td>
</tr><tr>
<td>Browser version</td><td><%=MyBrow.version%></td>
</tr><tr>
<td>Frame support?</td><td><%=MyBrow.frames%></td>
</tr><tr>
<td>Table support?</td><td><%=MyBrow.tables%></td>
</tr><tr>
<td>Sound support?</td><td><%=MyBrow.backgroundsounds%></td>
</tr><tr>
<td>Cookies support?</td><td><%=MyBrow.cookies%></td>
</tr><tr>
<td>VBScript support?</td><td><%=MyBrow.vbscript%></td>
</tr><tr>
<td>JavaScript support?</td><td><%=MyBrow.javascript%></td>
</tr>
</table>

</body>
</html>

Run instance»

Click the "Run instance" button to view the online instance

Output:

##Sound support?TrueCookies support?TrueVBScript support?TrueJavaScript support?True

Browscap.ini file

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

This part is not a tutorial 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]

Client OSWinNT
Web BrowserIE
Browser version5.0
Frame support?True
Table support?True
#ParametersDescription
commentsOptional. Any line of code starting with a semicolon is ignored by the BrowserType object.
HTTPUserAgentHeaderOptional. Specifies the HTTP User Agent header associated with the browser-property value declaration set in propertyN. Wildcards are allowed.
browserDefinitionOptional. Specifies the HTTP User Agent header-string of a browser to use as a parent browser. The current browser's definition will inherit all property values ​​declared in the parent browser's definition.
propertyNOptional. Specifies browser properties. The following table lists some of the possible properties:
  • ActiveXControls - Support ActiveX® controls?

  • Backgroundsounds - Support background sounds?

  • Cdf - Support channel definition format for webcasting?

  • Tables - Tables supported?

  • Cookies - Support cookies?

  • Frames - Support frames?

  • Javaapplets - Support Java applets?

  • Javascript - JScript supported?

  • Vbscript - VBScript supported?

  • Browser - Specifies the name of the browser

  • Beta - Is the browser beta software?

  • Platform - specifies the platform on which the browser runs

  • Version - specifies the version number of the browser

valueNOptional. Specifies the value of propertyN. Can be a string, an integer (prefixed with #), or a Boolean value.
defaultPropertyNOptional. Specifies the name of a browser property that is assigned a default value if none of the defined HTTPUserAgentHeader values ​​matches the HTTP User Agent header sent by the browser.
defaultValueNOptional. Specifies the value of defaultPropertyN. Can be a string, an integer (prefixed with #), or a Boolean value.

"Browscap.ini" 文件可能如下所示:

;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