SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript redirect based on browser type

    hey guys, i've asked a question on the css forum and got great responses so here's one on javascript.

    i've been searching the net for a while for a javascript redirect so that i can redirect IE6 browsers to a page that asks them to update. i'm sure i'm not alone on here in wishing that all ie6 users would just update finally, but they haven't yet. i'm also sure that i'm not alone in discovering that my site looks fine on all browsers but this one.

    so my question is this, what's wrong with my code? i found a few and this one seems to work best but it redirects IE7 as well. my code is this:

    <script LANGUAGE="JavaScript">

    function browser_check()
    {
    var name = navigator.appName;
    var version = parseInt(navigator.appVersion);
    go(name, version)
    }

    function go(name, version)
    {
    if(name == "Microsoft Internet Explorer" && version <=6)
    {
    location.href="redirected url"
    }
    }
    </script>
    it redirects ie 6 and ie 7, but i only want it to redirect 6 and lower. why is my "less than or equal to" not working properly?

    thanks in advance!

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's no "perfect" way of checking for browsers but this one comes close: http://www.quirksmode.org/js/detect.html
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank jimmy, i've read through that and i hate to be this guy, but i'm really not versed well enough in javascript to interpret what they're saying and then implementing it into reality.

    with the code i've got now, it's all working except for the browser version check. if i could just get that one bit sorted out...

    print designers weren't meant for this

  4. #4
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    haven't figured out what's wrong with my code, but i did find this website

    http://www - dot -daobydesign - dot - com/blog/2007/06/detect-redirect-script-for-internet-explorer-ie/

    it does exactly what i want it to do.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Why not use conditional comments?
    http://wsabstract.com/javatutors/con...lcompile.shtml

    Code javascript:
    function go(name, version)
    {
    /*@cc_on
       /*@if (@_jscript_version <= 5.6)
          location.href="redirected url";
       @else @*/
          // browser is > IE6 or other browser
       /*@end
    @*/
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that's basically what this code i found does, only it does it through an external js file. but i will try your code next time i need to do this.


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
  •