Componente de capacidades del navegador ASP
Componente de capacidades del navegador ASP
El componente Capacidades del navegador ASP crea un objeto BrowserType que determina el tipo, las capacidades y el número de versión del navegador de un visitante.
Cuando un navegador se conecta a un servidor, también se envía un encabezado de agente de usuario al servidor. Este encabezado contiene información sobre el navegador.
El objeto BrowserType compara la información del encabezado con la información de un archivo en el servidor llamado "Browscap.ini".
Si hay una coincidencia entre el tipo de navegador y el número de versión en el encabezado y la información en el archivo "Browscap.ini", el objeto BrowserType se puede usar para enumerar las propiedades del navegador coincidente. Si no hay ninguna coincidencia para el tipo de navegador y el número de versión en el archivo Browscap.ini, establecerá todas las propiedades en "DESCONOCIDO".
Sintaxis
<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>
Ejemplo de capacidades del navegador ASP
El siguiente ejemplo crea un objeto BrowserType en un archivo ASP y muestra algunas de las capacidades de su navegador:
Ejemplo
<!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>
Producción:
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 |
El archivo Browscap.ini
El archivo "Browscap.ini" se utiliza para declarar propiedades y establecer valores predeterminados para los navegadores.
Esta sección no es un tutorial sobre cómo mantener los archivos "Browscap.ini", solo le muestra lo básico; para que tenga una idea de qué se trata el archivo.
El archivo "Browscap.ini" puede contener lo siguiente:
[;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 archivo "Browscap.ini" podría verse así:
;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