ASP 浏览器功能成分


ASP 浏览器功能组件

ASP 浏览器功能组件创建一个 BrowserType 对象,该对象确定访问者浏览器的类型、功能和版本号。

当浏览器连接到服务器时,用户代理标头也会发送到服务器。该标头包含有关浏览器的信息。

BrowserType 对象将标头中的信息与服务器上名为 "Browscap.ini" 的文件中的信息进行比较。

如果标头中的浏览器类型和版本号与 "Browscap.ini" 文件中的信息相匹配,则可使用 BrowserType 对象列出匹配浏览器的属性。如果 Browscap.ini 文件中的浏览器类型和版本号不匹配,则会将每个属性设置为 "UNKNOWN"。

语法

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

ASP 浏览器功能示例

下面的示例在 ASP 文件中创建一个 BrowserType 对象,并显示浏览器的一些功能:

示例

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

输出:

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

"Browscap.ini" 文件用于声明属性并设置浏览器的默认值。

本节不是关于如何维护 "Browscap.ini" 文件的教程,它仅向您展示基础知识;这样您就可以了解该文件的全部内容。

"Browscap.ini" 文件可以包含以下内容:

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

Parameter Description
comments Optional. Any line that starts with a semicolon are ignored by the BrowserType object
HTTPUserAgentHeader Optional. Specifies the HTTP User Agent header to associate with the browser-property value statements specified in propertyN. Wildcard characters are allowed
browserDefinition Optional. Specifies the HTTP User Agent header-string of a browser to use as the parent browser. The current browser's definition will inherit all of the property values declared in the parent browser's definition
propertyN Optional. Specifies the browser properties. The following table lists some possible properties:
  • ActiveXControls - Support ActiveX controls?
  • Backgroundsounds - Support background sounds?
  • Cdf - Support Channel Definition Format for Webcasting?
  • Tables - Support tables?
  • Cookies - Support cookies?
  • Frames - Support frames?
  • Javaapplets - Support Java applets?
  • Javascript - Supports JScript?
  • Vbscript - Supports VBScript?
  • Browser - Specifies the name of the browser
  • Beta - Is the browser beta software?
  • Platform - Specifies the platform that the browser runs on
  • Version - Specifies the version number of the browser
valueN Optional. Specifies the value of propertyN. Can be a string, an integer (prefix with #), or a Boolean value
defaultPropertyN Optional. Specifies the name of the browser property to which to assign a default value if none of the defined HTTPUserAgentHeader values match the HTTP User Agent header sent by the browser
defaultValueN Optional. Specifies the value of defaultPropertyN. Can be a string, an integer (prefix 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