Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking browser type and version

Status
Not open for further replies.

spacehawk

Programmer
May 17, 2000
30
US
Can anyone find the problem in this code?

<%
Set bc = Server.CreateObject(&quot;MSWC.BrowserType&quot;)
If bc.browser = &quot;Netscape&quot; AND bc.version >= &quot;5.0&quot; then Response.Redirect(&quot;defaultie.asp&quot;)
End if
If bc.browser = &quot;Microsoft Internet Explorer&quot; AND bc.version >= &quot;4.0&quot; then Response.Redirect(&quot;defaultie.asp&quot;)
End If
%>

We are trying to redirect users to the page that will display right on their browser, but nothing is being redirected.

Thanks,
 
<%
' Alexander Granberg created this ASP 5/3 2001 alexander@lara.se
Dim Q
Dim strUA
Dim InStr

q = Chr(34)

strUA = Request.ServerVariables(&quot;HTTP_USER_AGENT&quot;)
Response.Write &quot;<p><font class=&quot;&q&&quot;verdana&quot;&q&&quot; size=&quot;&q&&quot;2&quot;&q&&quot;>The ServerVariables HTTP_User_Agent string is: <b>&quot;&strUA&&quot;</b></font></p>&quot;
If InStr(strUA, &quot;MSIE&quot;) Then
Response.Write &quot;<p><font class=&quot;&q&&quot;verdana&quot;&q&&quot; size=&quot;&q&&quot;2&quot;&q&&quot;>Your browser is Internet Explorer</font></p>&quot;
'Response.Redirect(&quot;defaultie.asp&quot;)
ElseIf InStr(strUA, &quot;Mozilla&quot;) Then
Response.Write &quot;<p><font class=&quot;&q&&quot;verdana&quot;&q&&quot; size=&quot;&q&&quot;2&quot;&q&&quot;>Your browser is proberbly Netscape.</font></p>&quot;
' Response.Redirect(&quot;defaultie.asp&quot;)
End If
%>
 
What about the version number check? Our problem is that Netscape 6 does not do a lot of the things earlier netscapes did. We just don't use it, but apparently some of our users do. We are trying to redirect it, but not the older Netscapes.

Thanks,
 
Well just run the script in a Netscape 6 and you'll see thge string contains the word &quot;Gecko&quot;

The command: Request.ServerVariables(&quot;HTTP_USER_AGENT&quot;)
Returns this in NS6:(Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; m18) Gecko/20001108 Netscape6/6.0)

So simply change the following:

Instead of using &quot;Mozilla&quot; as the word to look up in the string use &quot;Gecko&quot; and it should do fine!
Old: ElseIf InStr(strUA, &quot;Mozilla&quot;) Then
New: ElseIf InStr(strUA, &quot;Gecko&quot;) Then

It should do the job for you since now it only redirect NS6 users since the Gecko term in only available in NS6.

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top