Web Analytics Made Easy -
StatCounter browser detection not working - CodingForum

Announcement

Collapse
No announcement yet.

browser detection not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • browser detection not working

    Hey all,

    I'm using the following script to detect the users browser and then redirect after a few seconds to a javascript or non-javascript page. (The javascript I used only works in IE)

    <head>
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    redirTime = "2500";
    redirURL = "frameset_a.htm"; //with javascript version of menu - ie compatible
    redirURL2 = "frameset_b.htm"; //with non-javascript version of menu
    // End-->
    </head>


    <body onLoad="redirTimer()">
    <script language="Javascript">
    <!-- Hide script from old browsers
    if (navigator.appName == "Microsoft Internet Explorer") {
    function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); }
    }

    else {
    function redirTimer() { self.setTimeout("self.location.href = redirURL2;",redirTime);
    }
    }

    // End hiding script from old browsers -->
    </script>
    </body>

    It's always loading the non-javascript page, whether I am in IE or another browser. Why can't it detect IE? Did I write something wrong in that line of script? I have never done browser detection before so any help would be appreciated.

    Thanks,
    geminian

  • #2
    Code:
    if (navigator.appName == "Microsoft Internet Explorer")
      setTimeout('location.href =  "' + redirURL +'"', redirTime);
    else
      setTimeout('location.href =  "' + redirURL2 +'"', redirTime);
    or this: (better and clearer)
    Code:
    if (navigator.appName == "Microsoft Internet Explorer")
      setTimeout(function(){location.href = redirURL}, redirTime);
    else
      setTimeout(function(){location.href = redirURL2}, redirTime);
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      Thanks glenngv! It works perfectly!

      And you're right, the second version is much clearer and easier to understand.

      geminian

      Comment

      Working...
      X