Component ng Browser Capabilities ng ASP

实例

Browser Capabilities 组件
本例演示如何测定每一个访问网站的浏览器的类型、性能以及版本号。

Component ng Browser Capabilities ng ASP

ASP Browser Capabilities 组件会创建一个 BrowserType 对象,这个对象可测定访问者浏览器的类型、性能以及版本号。

当浏览器连接到服务器时,就会向服务器发送一个 HTTP User Agent 报头。这个报头包含着有关浏览器的信息(比如浏览器类型和版本号)。BrowserType 对象会把报头中的信息与服务器上名为 "Browscap.ini" 的文件中的信息作比较。

如果标题中被发送的浏览器类型和版本号和 "Browsercap.ini" 文件中信息可以匹配,那么我们就可以使用 BrowserType 对象列出这个匹配的浏览器的相关属性。如果上述情况不匹配,这个对象会把每个属性设置为 "UNKNOWN"。

语法

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

下面的例子对在 ASP 文件中创建一个 BrowserType 对象,并显示一个展示当前浏览器性能的表格:

<html>
<body>
<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>
<table border="1" width="100%">
<tr>
<th>OS klien</th>
<th><%=MyBrow.platform%></th>
</tr><tr>
<td >Browser Web</td>
<td ><%=MyBrow.browser%></td>
</tr><tr>
<td> bersih browser</td>
<td><%=MyBrow.version%></td>
</tr><tr>
<td>Angka frame?</td>
<td><%=MyBrow.frames%></td>
</tr><tr>
<td>Angka tabula?</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>

輸出:

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文件

"Browsercap.ini" 文件用於聲明屬性,並設置各瀏覽器的默認值。

本節內容不是關於如何 Browscap.ini 文件的操作教學,我們只提供一些關於 "Browsercap.ini" 的基礎知識和概念。

"Browsercap.ini" 文件可包含下面的信息:

[;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 Optional. Specify the HTTP User Agent header-string of a browser 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:
  • ActiveXControls - Does it support ActiveX controls?
  • Backgroundsounds - Does it support background sounds?
  • Cdf - Does it support the Channel Definition Format (CDF) for network broadcasting (Webcasting)?
  • Tables - Does it support tables?
  • Cookies - Does it support cookies?
  • Frames - Does it support frames?
  • Javaapplets - Does it support Java applets?
  • Javascript - Does it support JScript?
  • Vbscript - Does it support VBScript?
  • Browser - Define the name of the browser
  • Beta - Is the browser beta software?
  • Platform - Specify the platform on which the browser runs
  • Version - Specify the browser version number.
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