Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts

    help with my script ???

    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

    Code:
    <%
    
    Set objBCap = Server.CreateObject("MSWC.BrowserType")
    
    If CInt(objBCap.Version) > 4 And (objBCap.javascript = True) Then
    	Response.Clear
     	Response.Redirect "http://www.bbb.com/index.asp"
    
    	Else
    
     	Response.Clear
     	Response.Redirect "http://www.bbb.com/no_js.asp"
    End If
    %>
    Can someone help me figure out wtf? Did I miss something somewhere?

    Thanks

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    have you tried to get the values using response.write?

    Code:
    <%
    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.Clear
          'Response.Redirect "http://www.bbb.com/index.asp"
    'Else
          'Response.Clear
          'Response.Redirect "http://www.bbb.com/no_js.asp"
    'End If
    %>

  • #3
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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

  • #5
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    D'oh Because Mozilla is version is less than 4 it redirects to the appropriate so it does work. I then added

    Code:
    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?

  • #6
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #7
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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

  • #8
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    I understand that, but you don't need the browser version to know if script is enabled, do you?
    Two different animals.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #9
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •