Komponen Browser Capabilities ASP

Contoh

Komponen Kepemahaman Pelayar ASP
Contoh ini menunjukkan bagaimana menentukan jenis, kinerja, dan versi pelayar setiap pengunjung situs web.

Komponen Browser Capabilities ASP

Komponen ASP Browser Capabilities akan membuat objek BrowserType, objek ini dapat menentukan jenis, kinerja, dan versi pelayar pengunjung.

Ketika pelayar terhubung ke server, pelayar akan mengirimkan sebuah header HTTP User Agent. Header ini mengandung informasi tentang pelayar (seperti jenis dan versi pelayar). Objek BrowserType akan membandingkan informasi di header dengan informasi di berkas "Browscap.ini" yang ada di server.

Jika jenis dan versi pelayar yang dikirim dalam judul dapat dicocokkan dengan informasi di berkas "Browsercap.ini", maka kita dapat menggunakan objek BrowserType untuk daftar properti pelayar yang cocok. Jika hal ini tidak cocok, objek ini akan mengatur setiap properti menjadi "UNKNOWN".

Syarat

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

Contoh di bawah ini untuk membuat objek BrowserType dalam berkas ASP dan menampilkan jadwal kinerja pelayar saat ini:

<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 >Pelayar Web</td>
<td ><%=MyBrow.browser%></td>
</tr><tr>
<td>Versi pelayar</td>
<td><%=MyBrow.version%></td>
</tr><tr>
<td>Tabungan bingkai?</td>
<td><%=MyBrow.frames%></td>
</tr><tr>
<td>Tabungan tabal?</td>
<td><%=MyBrow.tables%></td>
</tr><tr>
<td>Dukungan Suara?</td>
<td><%=MyBrow.backgroundsounds%></td>
</tr><tr>
<td>Dukungan Cookies?</td>
<td><%=MyBrow.cookies%></td>
</tr><tr>
<td>Dukungan VBScript?</td>
<td><%=MyBrow.vbscript%></td>
</tr><tr>
<td>Dukungan JavaScript?</td>
<td><%=MyBrow.javascript%></td>
</tr>
</table>
</body>
</html>

Output:

OS Klien WinNT
Pelayar Web IE
Versi Pelayar 5.0
Dukungan Frame? True
Dukungan Tabel? True
Dukungan Suara? True
Dukungan Cookies? True
Dukungan VBScript? True
Dukungan JavaScript? True

Fail Browscap.ini

Fail "Browsercap.ini" digunakan untuk menyatakan sifat dan menetapkan nilai lalai bagi setiap pelayar.

Kandungan ini bukan tentang pengajaran bagaimana fail Browscap.ini, kami hanya memberikan sedikit pengertian asas dan konsep tentang "Browsercap.ini".

"Browsercap.ini" fail boleh mengandungi maklumat di bawah ini:

[;comments]
[HTTPUserAgentHeader] 
[parent=browserDefinition]
[property1=value1]
[propertyN=valueN] 
[Default Browser Capability Settings]
[defaultProperty1=defaultValue1]
[defaultPropertyN=defaultValueN] 
Parameter Deskripsi
comments Pilihan. Setiap baris kod yang bermula dengan titik bertindih diabaikan oleh objek BrowserType
HTTPUserAgentHeader Pilihan. Petikan tajuk berkhidmat pelanggan HTTP yang berkaitan dengan nilai browser-property yang ditetapkan di propertyN. Ia membenarkan penggunaan wakil.
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 the declared property values in the parent browser's definition.
propertyN Optional. Specify the browser properties. The following table lists some possible properties:
  • ActiveXControls - Is ActiveX controls supported?
  • Backgroundsounds - Is background sound supported?
  • Cdf - Is Channel Definition Format (CDF) for network broadcasting (Webcasting) supported?
  • Tables - Is tables supported?
  • Cookies - Is cookies supported?
  • Frames - Is frames supported?
  • Javaapplets - Is Java applets supported?
  • Javascript - Is JScript supported?
  • Vbscript - Is VBScript supported?
  • 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 defined in the HTTPUserAgentHeader that matches the HTTP user agent header sent by the browser, then this property is assigned a default value.
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