SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast wwright's Avatar
    Join Date
    Nov 2002
    Location
    Florida
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Browser detection & routing

    Hi All,

    O.k I have this little script that I want to use to detect which browser is being used and direct it to the appropriate page, depending on whether it's ie or netscape.

    The code:

    <script language="JavaScript">
    function browserRouting() {
    bname = navigator.appname;
    bVer = parseInt(navigator.appVersion);
    if (bname == "Netscape" && bVer >=3) parent.location='http://www.anywhere.com'
    else if (bname == "Microsoft Internet Explorer" && bVer >=2) parent.location='http://www.here.com'
    else parent.location='http://www.orhere.com';
    }
    </script>

    My problem is, I'm new to javascripting an don't know where to put the script. I put it in the <head> tag, <body> tag, in between the <head> and <body> tag but it doesn't work. I don't get any errors but it does not go to the specified page.

    Any thoughts

    Thanks,
    wwright

  2. #2
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I've removed your other thread as double posting isn't allowed No harm done though
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  3. #3
    SitePoint Enthusiast wwright's Avatar
    Join Date
    Nov 2002
    Location
    Florida
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am aware of the syntax errors of the bName and appName and corrected them and get the same results..?

    Any thoughts, wwright

  4. #4
    SitePoint Enthusiast wwright's Avatar
    Join Date
    Nov 2002
    Location
    Florida
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I figures it out.

    Had to add <body onload="browserRouting()">

    Learn something everyday

    Thanks wwright

  5. #5
    SitePoint Guru bronze trophy blufive's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know this isn't the question you're asking, but javascript browser detection is more complicated than the code above suggests. Go read this article


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
  •