[thelist] Re: Browser Detection

Andre Gaulin gaulin at mac.com
Fri Feb 23 13:53:16 CST 2001


hey everyone...

i know this whole browser detection thread started with a request for a
javascript detection scheme, but i wrote this one in ASP a while ago and i
have found it to be pretty solid.  it is great for detecting and customizing
CSS and other browser specific stuff, even WAP stuff.  any comments on it,
or suggestions to improve it are more than welcome..

CODE IS BELOW...

andre

<!-- WML DETECTION FIRST -->
<%
Dim sBOTBrowser
sBOTBrowser = Request.ServerVariables("HTTP_USER_AGENT")
sBOTBrowser2 = Request.ServerVariables("HTTP_ACCEPT")
if Left(sBOTBrowser, 4) = "UP.B" or _
   Left(sBOTBrowser, 4) = "Noki" or _
   Left(sBOTBrowser, 4) = "Eric" or _
   Instr(sBOTBrowser2, "wml") <> 0 then %>
<!-- WML INCLUDE HERE -->

<!-- WINDOWS -->
<%Elseif InStr(sBOTBrowser, "Win") >0 Then
Select Case True
 Case InStr(sBOTBrowser, "MSIE") >0 AND InStr(sBOTBrowser, "Mozilla/3.") >0
%>
<!-- IE 3 stuff --> <p>IE3 WIN</p>
<% Case InStr(sBOTBrowser, "MSIE") >0 AND InStr(sBOTBrowser, "Mozilla/4.")
>0 %>
<!-- IE 4+ stuff --> <p>IE4+ WIN</p>
<% Case InStr(sBOTBrowser, "Mozilla/3.") >0 %>
<!-- NETSCAPE 3 STUFF --><p>NETSCAPE 3 WIN </p>
<% Case InStr(sBOTBrowser, "Mozilla/4.") >0 %>
<!-- NETSCAPE 4 STUFF --><p>NETSCAPE 4 WIN </p>
<% Case InStr(sBOTBrowser, "Mozilla/5.") >0 %>
<!-- NETSCAPE 5 STUFF - MAY BE IRRELEVANT AND CAN GO WITH
MSIE --><p>NETSCAPE 5 WIN </p>
<% Case Else %>
<!-- ALL OTHER STUFF - OPERA, ETC> --><p>OTHER STUFF PC</p>
<% End Select %>

<!-- MAC DETECTION -->
<%Elseif InStr(sBOTBrowser, "Mac") >0 Then
Select Case True
 Case InStr(sBOTBrowser, "MSIE 4.5") >0 %>
<!-- IE 4.5+ stuff --><p>IE 4.5+ MAC</p>
<% Case InStr(sBOTBrowser, "MSIE 5.0") >0 %>
<!-- IE 5+ stuff --><p>IE 5+ MAC</p>
<% Case InStr(sBOTBrowser, "MSIE 5.5") >0 %>
<!-- IE 5+ stuff --><p>IE 5.5 MAC</p>
<% Case InStr(sBOTBrowser, "Mozilla/4.") %>
<!-- NETSCAPE 4+ stuff --><p>NETSCAPE 4+ MAC</p>
<% Case InStr(sBOTBrowser, "Mozilla/5.") >0 %>
<!-- NETSCAPE 5+ stuff --><p>NETSCAPE 5+ MAC</p>
<% Case Else %>
<!-- EVERYTHING ELSE - OPERA, OMNIWEB, ETC. --><p>OTHER STUFF MAC</p>
<% End Select%>

<!-- ANYTHING ELSE NON MAC OR WINDOWS OR WML -->
<%Else%>
<!-- LOW TECH/NON WIN-MAC INCLUDE HERE (typically netscape 3 compatible or a
redirect to PLEASE UPGRADE/NOT SUPPORTED --><p>OTHER STUFF NON-WIN-MAC</p>
<%End If%>






More information about the thelist mailing list