Composant de capacités du navigateur ASP
Composant de capacités du navigateur ASP
Le composant ASP Browser Capabilities crée un objet BrowserType qui détermine le type, les capacités et le numéro de version du navigateur d'un visiteur.
Lorsqu'un navigateur se connecte à un serveur, un en-tête d'agent utilisateur est également envoyé au serveur. Cet en-tête contient des informations sur le navigateur.
L'objet BrowserType compare les informations de l'en-tête avec les informations d'un fichier sur le serveur appelé "Browscap.ini".
S'il existe une correspondance entre le type de navigateur et le numéro de version dans l'en-tête et les informations du fichier « Browscap.ini », l'objet BrowserType peut être utilisé pour répertorier les propriétés du navigateur correspondant. S'il n'y a pas de correspondance pour le type de navigateur et le numéro de version dans le fichier Browscap.ini, il définira chaque propriété sur "UNKNOWN".
Syntaxe
<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>
Exemple de capacités du navigateur ASP
L'exemple ci-dessous crée un objet BrowserType dans un fichier ASP et affiche certaines des fonctionnalités de votre navigateur :
Exemple
<!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>
Sortir:
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 |
Le fichier Browscap.ini
Le fichier "Browscap.ini" permet de déclarer des propriétés et de définir des valeurs par défaut pour les navigateurs.
Cette section n'est pas un tutoriel sur la façon de maintenir les fichiers "Browscap.ini", elle ne vous montre que les bases ; ainsi vous avez une idée de ce qu'est le dossier.
Le fichier "Browscap.ini" peut contenir les éléments suivants :
[;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 |
Un fichier "Browscap.ini" pourrait ressembler à ceci :
;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