当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP > ASP BrowserCap

ASP
ASP Drive
ASP File
ASP Folder
ASP Dictionary
ASP ADO
ASP AdRotator
ASP BrowserCap
ASP Content Linking
ASP Content Rotator
ASP Quick Ref
ASP 摘要
ASP 实例

ASP BrowserCap


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 501 ::
收藏到网摘: n/a

Examples
举例

The Browser Capabilities Component
This example shows how to determine the type, capabilities and version number of each browser visiting your site.
浏览器属性组件
这个例子告诉我们如何获取访问你网站的浏览器的类型、属性以及版本号。


ASP Browser Capabilities Component
ASP浏览器属性组件

The ASP Browser Capabilities component creates a BrowserType object that determines the type, capabilities and version number of each browser that visits your site.
通过ASP浏览器属性组件可以建立一个BrowserType对象,通过这个对象获取每一个访问你网站的浏览器的类型、属性以及版本号。

When a browser connects to a server, an HTTP User Agent Header is also sent to the server. This header contains information about the browser (like browser type and version number). The BrowserType object then compares the information in the header with information in a file on the server called "Browscap.ini".
当一个浏览器链接到一个服务器上时,一个HTTP的标题也会被发送到服务器。这个标题包括了浏览器的所有信息(如浏览器类型以及版本号)。这个BrowserType对象可以把HTML标题信息与服务器内一个名为“Browsercap.ini”的文件进行比较。

If there is a match between the browser type and version number sent in the header and the information in the "Browsercap.ini" file, you can use the BrowserType object to list the properties of the matching browser. If there is no match for the browser type and version number in the Browscap.ini file, it will set every property to "UNKNOWN".
如果这个浏览器的类型、版本号与“Browsercap.ini”文件内的信息相匹配,你可以使用BrowserType对象把这个相匹配的浏览器的属性列出来。如果上述内容不相匹配,则它对所有属性的回答是“UNKNOW(不知道)”。

Syntax语法:

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

The example below creates a BrowserType object in an ASP file, and displays a table showing some of the capabilities of the current browser:
下面的例子在ASP文件中建立了一个BrowserType对象,它会显示一个当前浏览器属性的列表信息:

<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


The Browscap.ini File
Browsercap.ini文件

The "Browsercap.ini" file is used to declare properties and to set default values for browsers.
“Browsercap.ini”文件是用来输出浏览器的属性以及设置浏览器的默认变量值的。

This section is not a tutorial on how to maintain "Browsercap.ini" files, it only shows you the basics; so you get an idea what a "Browsercap.ini" file is all about.
这个部分并不是关于“Browsercap.ini”文件的具体教程,它只是阐明了一个关于“Browsercap.ini”的规则,让你可以明白“Browsercap.ini”文件的具体用处。

The "Browsercap.ini" file can contain the following:

[;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
可选组件。写在 “;”号之后,他将被BrowserType对象忽略
HTTPUserAgentHeader Optional. Specifies the HTTP User Agent header to associate with the browser-property value statements specified in propertyN. Wildcard characters are allowed
可选组件. 将HTTP的报头标题写入propertyN所指定的浏览器属性变量。允许使用通配符。
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
可选组件。将HTTP用户的浏览器中的报头标题字符串列入父一级浏览器。现有的浏览器定义将继承所有在父级浏览器中定义的属性变量。
propertyN Optional. Specifies the browser properties. The following table lists some possible properties:
可选组件.定义浏览器属性. 下面的列表罗列出了可能出现的属性:
  • ActiveXControls - Support ActiveX® controls?
    • ActiveXControls – 是否支持 ActiveX® 控件?
  • Backgroundsounds - Support background sounds?
    • Backgroundsounds -是否支持background 音乐?
  • Cdf - Support Channel Definition Format for Webcasting?
    • Cdf -是否支持Channel Definition Format for Webcasting(网络传播渠道的定义格式)?
  • Tables - Support tables?
    • Tables - 是否支持tables(列表)?
  • Cookies - Support cookies?
    • Cookies - 是否支持cookies?
  • Frames - Support frames?
    • Frames - 是否支持 frames(框架)?
  • Javaapplets - Support Java applets?
    • Javaapplets - 是否支持 Java 程序?
  • Javascript - Supports JScript?
    • Javascript - 是否支持 JScript?
  • Vbscript - Supports VBScript?
    • Vbscript - 是否支持 VBScript?
  • Browser - Specifies the name of the browser
    • Browser – 定义浏览器名称
  • Beta - Is the browser beta software?
    • Beta – 检查浏览器是否是测试版本
  • Platform - Specifies the platform that the browser runs on
    • Platform - 定义浏览器运行的平台
  • Version - Specifies the version number of the browser
    • Version – 定义浏览器的版本号
valueN Optional. Specifies the value of propertyN. Can be a string, an integer (prefix with #), or a Boolean value
可选组件. 定义propertyN变量值. 它可以使一个字符串,一个整数(定义式加上前缀“#”), 或者是一个布林(逻辑)变量
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
可选组件. 将浏览器的属性名称写入指定的默认变量中,如果HTTPUserAgentHeader 中的变量没有与浏览器中的HTTP中的报头文件相匹配。
defaultValueN Optional. Specifies the value of defaultPropertyN. Can be a string, an integer (prefix with #), or a Boolean value
可选组件。 定义defaultPropertyN变量值。它可以使一个字符串,一个整数(定义式加上前缀“#”), 或者是一个布林(逻辑)变量

A "Browsercap.ini" file might look something like this:
一个“Browsercap.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

评论 (0) All

登陆 | 还没注册?