Thành phần khả năng của trình duyệt ASP
Thành phần khả năng của trình duyệt ASP
Thành phần Khả năng của trình duyệt ASP tạo ra một đối tượng BrowserType xác định loại, khả năng và số phiên bản của trình duyệt của khách truy cập.
Khi trình duyệt kết nối với máy chủ, tiêu đề Tác nhân người dùng cũng được gửi đến máy chủ. Tiêu đề này chứa thông tin về trình duyệt.
Đối tượng BrowserType so sánh thông tin trong tiêu đề với thông tin trong một tệp trên máy chủ có tên "Browscap.ini".
Nếu có sự trùng khớp giữa loại trình duyệt và số phiên bản trong tiêu đề với thông tin trong tệp "Browscap.ini", đối tượng BrowserType có thể được sử dụng để liệt kê các thuộc tính của trình duyệt phù hợp. Nếu không có sự trùng khớp về loại trình duyệt và số phiên bản trong tệp Browscap.ini, nó sẽ đặt mọi thuộc tính thành "UNKNOWN".
Cú pháp
<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>
Ví dụ về khả năng của trình duyệt ASP
Ví dụ bên dưới tạo đối tượng BrowserType trong tệp ASP và hiển thị một số khả năng của trình duyệt của bạn:
Ví dụ
<!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>
Đầu ra:
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 |
Tệp Browscap.ini
Tệp "Browscap.ini" được sử dụng để khai báo các thuộc tính và đặt giá trị mặc định cho trình duyệt.
Phần này không phải là hướng dẫn về cách duy trì các tệp "Browscap.ini", nó chỉ hiển thị cho bạn những thông tin cơ bản; để bạn biết nội dung của tập tin đó là gì.
Tệp "Browscap.ini" có thể chứa những nội dung sau:
[;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:
|
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 |
Tệp "Browscap.ini" có thể trông giống như thế này:
;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