Latest web development tutorials

ASP Browser Capabilities

ASP Browser Capabilities component

ASP Browser Capabilities component creates a BrowserType object that can be measured in the visitor's browser type, capabilities and version number.

When a browser connects to the server, it will send a HTTP User Agent header to the server. The header contains information about the browser.

The BrowserType Browscap.ini header information server file named "Browscap.ini" of information for comparison.

If the header of the browser type and version number "Browsercap.ini" matching file information, then we can use the objects listed in this match BrowserType browser related properties. If there is no match, this object will set every property to "UNKNOWN".

grammar

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


ASP Browser Capabilities examples

The following example creates a BrowserType object in an ASP file, and display some information about the current browser performance:

Examples

<!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>

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

The demonstration >>

Browscap.ini file

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

This section is not a tutorial on how to maintain Browscap.ini file, we only provide some basic knowledge and concepts about "Browsercap.ini", so you would have a general understanding of the document.

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

[;comments]
[HTTPUserAgentHeader]
[parent=browserDefinition]
[property1=value1]
[propertyN=valueN]
[Default Browser Capability Settings]
[defaultProperty1=defaultValue1]
[defaultPropertyN=defaultValueN]

参数 描述
comments 可选项。任何起始于分号的代码行都被 BrowserType 对象忽略。
HTTPUserAgentHeader 可选项。规定与在 propertyN 中设定的 browser-property 值声明相关的 HTTP User Agent 报头。允许使用通配符。
browserDefinition 可选项。规定作为父浏览器使用的某个浏览器的 HTTP User Agent header-string。当前浏览器的定义会继承在父浏览器的定义中所有声明过的属性值。
propertyN 可选项。规定浏览器的属性。下面的表格列出了某些可能的属性:
  • ActiveXControls - 支持 ActiveX® 控件?
  • Backgroundsounds - 支持背景声音?
  • Cdf - 支持针对网络广播的频道定义格式?
  • Tables - 支持表格?
  • Cookies - 支持 cookies?
  • Frames - 支持框架?
  • Javaapplets - 支持 Java applets?
  • Javascript - 支持 JScript?
  • Vbscript - 支持 VBScript?
  • Browser - 规定浏览器的名称
  • Beta - 浏览器是否为 beta 软件?
  • Platform - 规定浏览器运行的平台
  • Version - 规定浏览器的版本号
valueN 可选项。规定 propertyN 的值。可为字符串、整数(前缀带 #)或者布尔值。
defaultPropertyN 可选项。规定浏览器属性的名称,假如已定义的 HTTPUserAgentHeader 值中没有值能与浏览器发送的 HTTP User Agent 报头相匹配,则为这个属性分配一个默认的值。
defaultValueN 可选项。规定 defaultPropertyN 的值。可为字符串、整数(前缀带 #)或者布尔值。

"Browscap.ini" file might look like:

;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