Results 1 to 3 of 3

Thread: Browser Redirection Based on Browser Version

  1. #1
    Join Date
    Jun 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Browser Redirection Based on Browser Version

    I can't figure out why the following code does not work. It's supposed to open a certain frame if a user is using a browser version 3 or higher, but it doesn't work. Can somebody show me a sample of some code that would do this, and actually work?

    Thank you

    <html>
    <head>
    <title>
    Rescue Africa
    </title>
    </head>
    <!-- This doesn't work at all. Why? See page 124 and 125 of HTML artistry-->
    <script language="JavaScript">
    var ver = navigator.appVersion;
    document.write('<frameset frameborder="0" border="0" cols="468, 424, 114,*"> ');
    document.write('<frameset frameborder="0" border="0" rows="232,30,253,*"> ');
    if (ver >= 3){
    document.write('<frame name="nav" src="topFace2.html" scrolling="no" marginwidth="0" /> ');
    }
    //This part of the script does not appear to be working. It's opening topFace1.html instead of
    //topFace2.html on IE 6.0
    else{
    document.write('<frame name="nav" src="topFace1.html" scrolling="no" marginwidth="0" /> ');
    }
    document.write('<frame name="subNav" src="crisis.html" scrolling="no" marginwidth="0" /> ');
    document.write('<frame name="bottom" src="bottomFace.html" scrolling="no" marginwidth="0" /> ');
    document.write('<frame name="blackRow" src="black.html" scrolling="no" marginwidth="0" /> ');
    document.write('</frameset> ');
    if (ver >= 3){
    document.write('<frame name="middle" src="crisisTXT.html" scrolling="no" marginwidth="0" /> ');
    }
    //This part of the script does not appear to be working. It's opening crisisTXTOldB.html instead of
    //crisisTXT.html on IE 6.0
    else{
    document.write('<frame name="middle" src="crisisTXTOldB.html" scrolling="no" marginwidth="0" /> ');
    }

    document.write('<frame name="right" src="right.html" scrolling="no" marginwidth="0" />');
    document.write('<frame name="blackCol" src="black.html" scrolling="no" marginwidth="0" />');
    document.write('</frameset>');
    </script>


    <noframes>
    <body>
    Your browser does not allow frames.
    </body>
    </noframes>

    </html>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,377
    Thanks
    77
    Thanked 3,421 Times in 3,382 Posts
    Blog Entries
    12

    Default

    'navigator.appVersion' returns this:

    4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705)

    and similar type strings when queried in javascript. It is never a number in the strict sense of the term. You have set the varaiable 'ver' to this string then you are doing a math operation on it:
    Code:
    var ver = navigator.appVersion;
    ....document.write stuff was here....
    if (ver >= 3)
    ver will never be greater than nor equal to 3. You might try this:
    Code:
    var ver = parseInt(navigator.appVersion);
    Using the navigator.appVersion string:

    4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705)

    this will set ver to 4.
    - John
    ________________________

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

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by nathaliaMota
    It's supposed to open a certain frame if a user is using a browser version 3 or higher
    Of the 'standard' browsers, all of them are beyond version 3. You won't be encountering NN3 or IE3, for example. You may not even encounter IE4 or NN4, so dump that junk.

    There's another reason to dump it: not all user agents follow Microsoft's version numbering. I believe the most recent version of Safari is 1.2, and Opera is at 8.0. I can't check what Safari reports as its version number, but I know Opera returns the true number, not an equivalent.

    The final reason is that not everyone enables client-side scripting. Basing a frameset document on a script will render the entire site useless. Simply telling someone that they don't support frames is equally dumb (for both users and search engines).

    Browser detection is flawed and almost always, useless. The far more useful information is what a browser can do. Read the browser detection entry in the comp.lang.javascript FAQ (including the link to the notes for more information).


    Quote Originally Posted by jscheuer1
    var ver = parseInt(navigator.appVersion);
    Unless one has a very specific reason, the parseInt function should never be called without the radix argument.

    Mike

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
  •