Web Analytics Made Easy -
StatCounter browser/version detection and redirection - CodingForum

Announcement

Collapse
No announcement yet.

browser/version detection and redirection

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

  • browser/version detection and redirection

    i am doing some things that only seem to work in IE6...is it possible to have the HTML detect what browser and version is being used, and if its not IE6 it will redirect them to a different place???

    thanks

  • #2
    Yes it is possible:

    Code:
    <script language="JavaScript">
    function redir()
    {
     var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1;
     if(!ie)
     {
      location.href="somefile.html";
     }
    }
    </script>
    
    <body onLoad="redir()">
    Scripting | JavaScripts | PerlScripts | Python Scripts | Articles | My Journal

    Comment


    • #3
      Here's a more "delicate" script that redirects depending on a variety of browsers: http://www.dynamicdrive.com/dynamicindex9/bredirect.htm
      - George
      - JavaScript Kit- JavaScript tutorials and 400+ scripts!
      - JavaScript Reference- JavaScript reference you can relate to.

      Comment


      • #4
        A more specific question

        Hello!

        The answers posted here before don't solve this question. It's easy to do it between NS, Opera and IE. But, how to detect and redirect between IE 6 and IE 5?

        I've the same problem, and another way to suggest how to solve it.

        It's easy to detect the brower type and version with the script below:

        <script>

        /*Displaying a user's browser type script
        By JavaScript Abstration (javascriptkit.com)
        Over 200+ free scripts here!
        */

        if (document.all)
        var version=/MSIE \d+.\d+/

        if (!document.all)
        document.write("You are using "+navigator.appName+" "+navigator.userAgent)
        else
        document.write("You are using "+navigator.appName+" "+navigator.appVersion.match(version))

        </script>

        This script displays the complete browser type for both, IE 6 and IE 5. So, how to get this answer and use it to redirect to a specific page?



        Elson Frَes
        Pop Box: visual, sound and verse poetry

        Comment


        • #5
          Here is a pretty complete sniffer that does object sniffing, as well as specific version sniffing as well.
          My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
          “Minds are like parachutes. They don't work unless they are open”
          “Maturity is simply knowing when to not be immature”

          Comment


          • #6
            Yes!!!!

            Tks, Beetle

            I do some cuts and adaptations in the script, on that page you suggested, and now it is functional:

            <head>
            <script LANGUAGE="JavaScript">
            <!-- hide JavaScript from non-JavaScript browsers
            // This script is a simplified adaptation from the
            // JavaScript Browser Sniffer
            // Eric Krok, Andy King, Michel Plungjan
            // see http://www.webreference.com/ for more information

            var agt=navigator.userAgent.toLowerCase();
            var appVer = navigator.appVersion.toLowerCase();
            var is_minor = parseFloat(appVer);
            var is_major = parseInt(is_minor);
            var iePos = appVer.indexOf('msie');
            if (iePos !=-1) {
            is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
            is_major = parseInt(is_minor);
            }
            var is_getElementById = (document.getElementById) ? "true" : "false";
            var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
            var is_documentElement = (document.documentElement) ? "true" : "false";
            var is_ie = ((iePos!=-1));
            var is_ie3 = (is_ie && (is_major < 4));
            var is_ie4 = (is_ie && is_major == 4);
            var is_ie4up = (is_ie && is_minor >= 4);
            var is_ie5 = (is_ie && is_major == 5);
            var is_ie5up = (is_ie && is_minor >= 5);
            var is_ie5_5 = (is_ie && (agt.indexOf("msie 5.5") !=-1));
            var is_ie5_5up =(is_ie && is_minor >= 5.5);
            var is_ie6 = (is_ie && is_major == 6);
            var is_ie6up = (is_ie && is_minor >= 6);
            // -->
            </script>
            </head>

            <body>

            <script LANGUAGE="JavaScript">
            <!--
            if (is_minor!=6)
            window.location.replace('somewhere.htm');
            //--></script>


            my best wishes and happy new year,

            Elson Frَes
            Pop Box: visual, sound and verse poetry

            Comment


            • #7
              If you only want IE6 you can cut your code down alot by only sniffing for it.

              Comment


              • #8
                Yes, Graeme, surely.

                Sweeping more the script:


                <script LANGUAGE="JavaScript">
                <!-- hide JavaScript from non-JavaScript browsers
                // This script is a simplified adaptation from the
                // JavaScript Browser Sniffer
                // Eric Krok, Andy King, Michel Plungjan
                // see http://www.webreference.com/ for more information
                var appVer = navigator.appVersion.toLowerCase();
                var is_minor = parseFloat(appVer);
                var is_major = parseInt(is_minor);
                var iePos = appVer.indexOf('msie');
                if (iePos !=-1) {
                is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
                is_major = parseInt(is_minor);
                }
                var is_ie = ((iePos!=-1));
                var is_ie6 = (is_ie && is_major == 6);
                var is_ie6up = (is_ie && is_minor >= 6);
                if (is_minor!=6)
                window.location.replace('croncal.htm');
                // -->
                </script>

                Tks.
                Elson Frَes
                Pop Box: visual, sound and verse poetry

                Comment

                Working...
                X