Componente de recursos do navegador ASP
Componente de recursos do navegador ASP
O componente ASP Browser Capabilities cria um objeto BrowserType que determina o tipo, os recursos e o número da versão do navegador de um visitante.
Quando um navegador se conecta a um servidor, um cabeçalho User Agent também é enviado ao servidor. Este cabeçalho contém informações sobre o navegador.
O objeto BrowserType compara as informações no cabeçalho com as informações em um arquivo no servidor chamado "Browscap.ini".
Se houver uma correspondência entre o tipo de navegador e o número da versão no cabeçalho e as informações no arquivo "Browscap.ini", o objeto BrowserType poderá ser usado para listar as propriedades do navegador correspondente. Se não houver correspondência para o tipo de navegador e o número da versão no arquivo Browscap.ini, todas as propriedades serão definidas como "UNKNOWN".
Sintaxe
<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>
Exemplo de recursos do navegador ASP
O exemplo abaixo cria um objeto BrowserType em um arquivo ASP e exibe alguns dos recursos do seu navegador:
Exemplo
<!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>
Saída:
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 |
O arquivo Browscap.ini
O arquivo "Browscap.ini" é usado para declarar propriedades e definir valores padrão para navegadores.
Esta seção não é um tutorial sobre como manter arquivos "Browscap.ini", apenas mostra o básico; para que você tenha uma ideia do que se trata o arquivo.
O arquivo "Browscap.ini" pode conter o seguinte:
[;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 |
Um arquivo "Browscap.ini" pode ser algo assim:
;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