ASP Browser Capabilities Component
- Previous Page ASP AdRotator
- Next Page ASP ContentLinking
Example
- Browser Capabilities component
- This example demonstrates how to determine the type, performance, and version number of each browser that visits the website.
ASP Browser Capabilities Component
The ASP Browser Capabilities component creates a BrowserType object that can determine the type, performance, 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 (such as browser type and version number). The BrowserType object compares the information in the header with the information in the file named "Browscap.ini" on the server.
If the browser type and version number sent in the title can be matched with 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 conditions do not match, this object will set each property to "UNKNOWN".
Syntax
<% Set MyBrow=Server.CreateObject("MSWC.BrowserType") %>
The following example demonstrates how to create a BrowserType object in an ASP file and display a table showing the current browser performance:
<html> <body> <% Set MyBrow=Server.CreateObject("MSWC.BrowserType") %> <table border="1" 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>
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 |
Browscap.ini file
"Browsercap.ini" file is used to declare properties and set default values for each browser.
This section is not a tutorial on how to use the Browscap.ini file; we only provide some basic knowledge and concepts about "Browsercap.ini".
"Browsercap.ini" file can include the following information:
[;comments] [HTTPUserAgentHeader] [parent=browserDefinition] [property1=value1] [propertyN=valueN] [Default Browser Capability Settings] [defaultProperty1=defaultValue1] [defaultPropertyN=defaultValueN]
Parameters | Description |
---|---|
comments | Optional. Any code line starting with a semicolon is ignored by the BrowserType object. |
HTTPUserAgentHeader | Optional. Declares the HTTP User Agent header related to the browser-property value set in propertyN. Wildcards are allowed. |
browserDefinition | Optional. Specify the HTTP User Agent header-string of a browser to be used as a parent browser. The current browser's definition will inherit all declared property values from the parent browser's definition. |
propertyN |
Optional. Specify the properties of the browser. The following table lists some possible properties:
|
valueN | Optional. Specify the value of propertyN. It can be a string, an integer (prefixed with #), or a logical value. |
defaultPropertyN | Optional. Specify the name of the browser property. If there is no value in the defined HTTPUserAgentHeader that matches the HTTP user agent header sent by the browser, then assign a default value to this property. |
defaultValueN | Optional. Specify the value of defaultPropertyN. It can be a string, an integer (prefixed with #), or a logical value. |
"Browsercap.ini" file will be similar to 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
- Previous Page ASP AdRotator
- Next Page ASP ContentLinking