Componente Browser Capabilities ASP
- Pagina precedente ASP AdRotator
- Pagina successiva ASP ContentLinking
Esempio
- Componente Browser Capabilities
- Questo esempio dimostra come determinare il tipo, le prestazioni e il numero di versione del browser di ogni visitatore del sito web.
Componente Browser Capabilities ASP
Il componente ASP Browser Capabilities crea un oggetto BrowserType, che può determinare il tipo, le prestazioni e il numero di versione del browser dell'utente.
Quando il browser si connette al server, invia un'intestazione HTTP User Agent al server. Questa intestazione contiene informazioni sul browser (ad esempio, il tipo e il numero di versione). L'oggetto BrowserType confronta le informazioni dell'intestazione con quelle nel file "Browscap.ini" sul server.
Se il tipo di browser e il numero di versione inviati nel titolo corrispondono alle informazioni nel file "Browsercap.ini", possiamo utilizzare l'oggetto BrowserType per elencare le proprietà del browser corrispondente. Se non corrispondono, questo oggetto imposta ogni proprietà a "UNKNOWN".
Sintassi
<% Set MyBrow=Server.CreateObject("MSWC.BrowserType") %>
Esempio sottostante su come creare un oggetto BrowserType in un file ASP e visualizzare una tabella che mostra le prestazioni del browser corrente:
<html> <body> <% Set MyBrow=Server.CreateObject("MSWC.BrowserType") %> <table border="1" width="100%"> <tr> <th>Sistema operativo del client</th> <th><%=MyBrow.platform%></th> </tr><tr> <td >Browser web</td> <td ><%=MyBrow.browser%></td> </tr><tr> <td>Versione del browser</td> <td><%=MyBrow.version%></td> </tr><tr> <td>Supporto per i frame?</td> <td><%=MyBrow.frames%></td> </tr><tr> <td>Supporto per la tabella?</td> <td><%=MyBrow.tables%></td> </tr><tr> <td>Supporto Audio?</td> <td><%=MyBrow.backgroundsounds%></td> </tr><tr> <td>Supporto Cookies?</td> <td><%=MyBrow.cookies%></td> </tr><tr> <td>Supporto VBScript?</td> <td><%=MyBrow.vbscript%></td> </tr><tr> <td>Supporto JavaScript?</td> <td><%=MyBrow.javascript%></td> </tr> </table> </body> </html>
Output:
Sistema operativo client | WinNT |
---|---|
Browser Web | IE |
Versione del browser | 5.0 |
Supporto Frame? | True |
Supporto Tabelle? | True |
Supporto Audio? | True |
Supporto Cookies? | True |
Supporto VBScript? | True |
Supporto JavaScript? | True |
File Browscap.ini
Il file "Browsercap.ini" viene utilizzato per dichiarare proprietà e impostare i valori predefiniti di ciascun browser.
Questa sezione non è un tutorial su come utilizzare il file Browscap.ini, forniamo solo alcune conoscenze di base e concetti su "Browsercap.ini".
"Browsercap.ini" il file può includere le seguenti informazioni:
[;comments] [HTTPUserAgentHeader] [parent=browserDefinition] [property1=value1] [propertyN=valueN] [Impostazioni predefinite del browser] [defaultProperty1=defaultValue1] [defaultPropertyN=defaultValueN]
Parametro | Descrizione |
---|---|
comments | Opzione. Ogni riga di codice che inizia con un punto e virgola viene ignorata dall'oggetto BrowserType |
HTTPUserAgentHeader | Opzione. Dichiarazione dell'intestazione HTTP User Agent relativa al valore di browser-property impostato in propertyN. È consentito l'uso dei caratteri jolly. |
browserDefinition | Optional. Specify the HTTP User Agent header-string of a browser to be used as a parent browser. The current browser's definition will inherit all declared property values from the parent browser's definition. |
propertyN |
Optional. Specify the properties of the browser. The following table lists some possible properties:
|
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 the defined HTTPUserAgentHeader value does not match any value sent by the browser's HTTP User Agent header, then assign a default value to this property. |
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
- Pagina precedente ASP AdRotator
- Pagina successiva ASP ContentLinking