Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: Browser Version detection and redirection

  1. #1
    Join Date
    Nov 2006
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Browser Version detection and redirection

    After googling endlessly and searching these forums, I have not found what I am loking for.

    Basically, I need a browser detection script that will detect what version of what browser the user is reading. My site works with IE 5.5SP2 and up, Netscape 7.2 and up, Opera 7.1 and up, and Firefox 1.0 and up (have not tested on any Mac browsers.

    What I want the script to do is once it's detected a version ofone of these browsers or higher, to continue loading the page. If it detects a lower version, or any other browser, I want it to direct users to a page telling them they are using an old or untested browser, where I have links to update the tested browsers and a link to continue to the site anyways

    One script I found isn't working, and I don't know Javascript. Can anyone help? The one I found causes a runtime error in IE 6 for Windows 2000 and doesn't do what it's supposed to. And, how do I specify that IE 5.5 has to be SP2?

    Code:
    <script type="text/javascript"> 
    <!-- 
    browserName=navigator.appName; 
    browserVer=parseInt(navigator.appVersion); 
    if ((browserName=="Netscape" && browserVer>=7.2) || (browserName=="Microsoft Internet Explorer" && browserVer>=5.5) ||  (browserName=="Opera" && browserVer>=7.1) || (browserName=="Mozilla Firefox" && browserVer>=1))    
      version="vernew"; 
    else 
      version="other"; 
    /* Newer browser URL */ 
    if (version=="vernew") 
      window.location="http://www.wnstudios.ca"; 
    /* Other browsers URL */ 
    else 
      window.location="http://www.wnstudios.ca/old.html"; 
    //--> 
    </script>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    From QuirksMode.org:

    Do not use this script. Newbies often overrate the importance of a browser detect. Read the Object detection page first.
    Almost any script that uses a browser detect is incorrect.
    That said, the script there is much better at it:

    http://www.quirksmode.org/js/detect.html
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2006
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Which script? The one they said NOT to use?

    So if I am supposed to use object detection, how am I supposed to know which objects I am supposed to have the script detect? I don't know Javascript and don't know all the intricicies of browsers and what exactly they mess up when rendering my site. My site is XHTML Transitional, and uses PHP includes, CSS, and Javascript, mainly the Ultimate Fade-in slideshow from this site.

    So what exactly I am supposed to tell the detection script to look for?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    In all likelihood XHTML is not required. In any case it certainly is a questionable choice as, many browsers still do not support it. So, having it as your DOCTYPE will throw them into quirks rendering, the least cross browser level of page rendering. A valid strict or transitional HTML DOCTYPE should be used wherever possible with HTML 4.01 Strict being the preferred one, if applicable, as most browsers will render it in a similar fashion.

    The Ultimate Fade-in slideshow already performs extensive object detection. That is why it is so cross browser friendly.

    Object detection is not for page redirection. It is for branching within a script. In most basic terms, it is a method used in writing scripts which first asks the browser if it can do a thing before requesting that it do so. If the browser cannot, a different method is posited, and so on until either the script finds a method that suits the browser or runs out of choices. If the choices become exhausted, a simpler method from the very beginnings of javascript is used, or the effect in question is skipped.

    For more on object detection see:

    http://www.quirksmode.org/js/support.html
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Nov 2006
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I have read that page before, and it's all fine and dandy, but it doesn't help me. I don't know how to write JavaScript. All I was looking for was something to direct everything but the browsers I specified to a different page. Example:

    Code:
    browser = navigator.appName
    ver = navigator.appVersion
    version = ver.substring(0,1)
    if (browser=="Internet Explorer") {
    if (version<="5.5")
    document.location.href="index2.html"
    }
    if (browser=="Netscape") {
    if (version<="7.2")
    document.location.href="index2.html"
    }
    if (browser=="Firefox") {
    if (version<="1.0")
    document.location.href="index2.html"
    }
    if (browser=="Opera") {
    if (version<="7.1")
    document.location.href="index2.html"
    }
    This works just fine for me, except I need something else that says "If the browser is anything but IE 5.5 SP2, Netscape 7.2, Firefox 1.0, or Opera 7.1, send it to thispage.html".

    Yes, yes, I know, "Don't use browser detection", etc etc. However, I WANT to use it. It's simple for me to change since I don't know Javascript, and it seems to work with the 2 browsers I am testing it on (IE 6 and NS 4.79).

    So is there any way to have the script do what I want, keeping in mind that I don't want to deal with object detection at the moment? I want this to work first so Ihave something while I figure out a better way of doing it. Thanks

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Assuming that your above code works, simply appending a redirect for the fall back page would do it. You see, if the browser fulfills any of the the criteria established by your tests, it will be redirected to index2.html. Otherwise, it will find its way to the bottom of that code segment where you can put this:

    Code:
    document.location.href="someother.html"
    Alternatively, if the redirect script is on the page that you want all other browsers to use, simply having nothing at the end of those tests will allow all other browsers to remain on that page. This is actually preferable as, then even non-javascript enabled browsers will have something t look at.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I want this to work first so Ihave something while I figure out a better way of doing it.
    Instead, try not using browser-specific features until you figure out a better way of doing it.
    Quote Originally Posted by jscheuer1
    A valid strict or transitional HTML DOCTYPE should be used wherever possible
    From a purely pragmatic point of view, a Transitional HTML DOCTYPE is just as bad (or worse) than an XHTML one. A Strict XHTML DOCTYPE will tend to throw browsers into Standards mode, even those that don't support it; however, since the HTML is malformed, they may behave unpredictably. HTML Transitional will cause all of today's common browsers to go into Quirks.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Nov 2006
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Just for the record, my site is coded in XHTML 1.0 Transitional.

    As for the
    Code:
    document.location.href="someother.html"
    When I include that line, alone or in an else clause, it redirects everything to that specified page, even if the browser is up to date. MAybe the script should be the other way around and say "if x-browser is version y.z or higher, load the page, otherwise go to index2.html"

    How would that be done? Simply changing the < to a > will make the browser run through the script endlessly.

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by eday_2010 View Post
    Just for the record, my site is coded in XHTML 1.0 Transitional.
    Probably not a good idea.

    Your other problem, with the redirect, is probably due to a faulty script to begin with. Try DD's:

    http://www.dynamicdrive.com/dynamicindex9/bredirect.htm
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey View Post
    A Strict XHTML DOCTYPE will tend to throw browsers into Standards mode, even those that don't support it
    Like NS4? I don't understand this logic. I thought XHTML was to be avoided and that it threw non-supportive browsers into quirks - shows how much attention I've been paying to all of this.

    I know views vary on this subject (the best DOCTYPE to use) and that is fine with me. I like the HTML 4.01 Transitional/loose:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    It appears to me to be about the same as strict (when it comes to rendering in the various browsers) while at the same time allowing for more tags and attributes than strict.

    Take that with the fact that I have never been a crusader for strict adherence to any particular standards. They'll change and/or be ignored by some browsers. I do like valid code though so, go figure.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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