There is a quite obscure asp component which might become useful in some - I believe exceptional - situations. The Browser Capabilities Component creates a BrowserType object which can be used to determine almost everything about a visitor's browser.
The component works quite easily. Every time a page is visited, the browser sends to the server a User Agent Header containing information about the browser itself. Those information are then compared by the BrowserType object to an ini file called "browscap.ini" that sits on the server. When there is a match, the BrowserType object stores different information about the visitor's browser.
Browscap.ini
Said that, it is very important to keep the "Browscap.ini" file updated. To do so you can visit the Browser Capabilities Project web site, where you can download an updated version of the file (hurray!).
How to use the object
The use of the BrowserType object is very simple.First of all, you have to create the object:
<%
Set bt = Server.CreateObject("MSWC.BrowserType")
%>
and then you can browse (no pun intended!) all the properties:
<table border="0" width="100%">
<tr>
<th>Client OS</th><th><%=bt.platform%></th>
</tr><tr>
<td >Web Browser</td><td ><%=bt.browser%></td>
</tr><tr>
<td>Browser version</td><td><%=bt.version%></td>
</tr><tr>
<td>Frame support?</td><td><%=bt.frames%></td>
</tr><tr>
<td>Table support?</td><td><%=bt.tables%></td>
</tr><tr>
<td>Sound support?</td><td><%=bt.backgroundsounds%></td>
</tr><tr>
<td>Cookies support?</td><td><%=bt.cookies%></td>
</tr><tr>
<td>VBScript support?</td><td><%=bt.vbscript%></td>
</tr><tr>
<td>JavaScript support?</td><td><%=bt.javascript%></td>
</tr>
</table>
And that's it!
Weren't you saying jQuery?
Oh, yes! You're right, I did write jQuery! That is because in the jquery library you can find one property of the global jQuery object that is called jQuery.browser.jQuery.browser can be used to detect the web browser type. It has 5 different flags:
- webkit
- safari (deprecated)
- opera
- msie
- mozilla
$.browser.webkit
$.browser.safari
$.browser.opera
$.browser.msie
$.browser.mozilla
The property will return "true" when there's a match between the flag and the web browser type (remember the header?). You can then use the property as in the following example:
if ( ($.browser.msie) ){
alert('IE 6')
}
Finally I must let you know that jQuery official api reference states, “The $.browser property is
deprecated in jQuery 1.3, but there are no immediate plans to remove
it.”
0 thoughts:
Post a Comment
Comments are moderated. I apologize if I don't publish comments immediately.
However, I do answer to all the comments.