View Full Version : help with my script ???

08-17-2005, 03:36 PM
I'm trying to redirect based on browser version and javascript being enabled. If the browser is version 4 or less it goes to a non js page. For some reason my script always goes to the no_js page regardless of version. Here is my code


Set objBCap = Server.CreateObject("MSWC.BrowserType")

If CInt(objBCap.Version) > 4 And (objBCap.javascript = True) Then
Response.Redirect "http://www.bbb.com/index.asp"


Response.Redirect "http://www.bbb.com/no_js.asp"
End If

Can someone help me figure out wtf? Did I miss something somewhere?


08-17-2005, 03:45 PM
have you tried to get the values using response.write?

Set objBCap = Server.CreateObject("MSWC.BrowserType")

response.write "browser version : " & CInt(objBCap.Version) & "<br>"
response.write "javascript enabled :" & objBCap.javascript

'just comment out the if statements
'If CInt(objBCap.Version) > 4 And (objBCap.javascript = True) Then
'Response.Redirect "http://www.bbb.com/index.asp"
'Response.Redirect "http://www.bbb.com/no_js.asp"
'End If

08-17-2005, 04:06 PM
I don't know if case matters, but the docs have "version" with a lower-case "v".

Also, I have no idea how it thinks it's going to get whether script is enabled or not, since no header info is sent telling a server that (last I checked...).
Supported is one thing. Enabled is another.

08-17-2005, 04:25 PM
Case doesn't seem to matter. I had another script tested with javascript support unchecked in Mozilla and it went to the appropriate page. Then I turned it on and it also went to the appropriate page. It's after I added the version property things stopped working

08-17-2005, 05:21 PM
D'oh Because Mozilla is version is less than 4 it redirects to the appropriate so it does work. I then added

If objBCap.Browser = "IE" Or objBCap.Browser = "Netscape" And CInt(objBCap.Version) > 4 Then

to test for browser but again it still comes out to version less than 4. So my question is, how do you separate Netscape 4 from the other Mozilla browsers?

08-17-2005, 07:36 PM
This is why browser detection is so bad.
What about new browsers? Konqueror? Safari? Firefox is still less than version 4. So is Avant Browser (which I use extensively as an IE clone/add-on).

Honestly, I'd suggest not using browser detection. It doesn't do anything useful for you anymore. Object detection is the way people do things now and it's much better.

For example, if you want to use document.getElementById, you test for it, not for browsers that support it.
if (document.getElementById) // do something
else // do something else

Don't forget that Opera can mask as IE, Avant Browser already masks as IE (I think), and Firefox can say whatever the user wants it to say.
Ditch the browser detection for anything other than stats and even then take it with a grain of salt.

08-17-2005, 08:34 PM
that would work great if I wanted to use Javascript but I'm looking to see if javascript isn't enabled, that is out the window. I got it work by using the

Request.ServerVariables("HTTP_USER_AGENT") and Server.Transfer

and looking for the Netscape 4 specific text in the string

08-18-2005, 03:02 PM
I understand that, but you don't need the browser version to know if script is enabled, do you?
Two different animals.

08-18-2005, 04:44 PM
My site design won't work on NN4 so I want to steer NN4 users (if there are any left) to another page and I thought I'd throw in the no javascript line as well.