ASP - Browserfunktionskomponente


ASP-Browserfunktionskomponente

Die ASP Browser Capabilities-Komponente erstellt ein BrowserType-Objekt, das den Typ, die Fähigkeiten und die Versionsnummer des Browsers eines Besuchers bestimmt.

Wenn ein Browser eine Verbindung zu einem Server herstellt, wird auch ein User-Agent-Header an den Server gesendet. Dieser Header enthält Informationen über den Browser.

Das BrowserType-Objekt vergleicht die Informationen im Header mit Informationen in einer Datei auf dem Server namens "Browscap.ini".

Bei einer Übereinstimmung zwischen Browsertyp und Versionsnummer im Header und den Angaben in der Datei „Browscap.ini“ können über das BrowserType-Objekt die Eigenschaften des passenden Browsers aufgelistet werden. Wenn der Browsertyp und die Versionsnummer in der Datei Browscap.ini nicht übereinstimmen, werden alle Eigenschaften auf „UNBEKANNT“ gesetzt.

Syntax

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

Beispiel für ASP-Browserfunktionen

Das folgende Beispiel erstellt ein BrowserType-Objekt in einer ASP-Datei und zeigt einige der Funktionen Ihres Browsers an:

Beispiel

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

Ausgabe:

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



Die Browscap.ini-Datei

Die Datei "Browscap.ini" wird verwendet, um Eigenschaften zu deklarieren und Standardwerte für Browser festzulegen.

Dieser Abschnitt ist kein Tutorial zur Verwaltung von "Browscap.ini"-Dateien, er zeigt Ihnen nur die Grundlagen; damit Sie eine Vorstellung davon bekommen, worum es in der Datei geht.

Die Datei "Browscap.ini" kann Folgendes enthalten:

[;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

Eine "Browscap.ini"-Datei könnte etwa so aussehen:

;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