Need help with javascript redirection

Discussion in 'JavaScript' started by warman2442, Jun 4, 2008.

  1. #1
    Hey

    Im trying to redirect users using anything BUT firefox, and if they are using firefox to just continue on threw the site.

    So something like.


    <html>
    <script>
    if(navigator.userAgent.indexOf("Firefox") != -1)
    {
    window.location = "http://www.i-code.co.uk";


    }
    else if(navigator.userAgent.indexOf("MSIE") != -1)
    {
    window.location = "http://www.i-code.co.uk";
    }
    else if(navigator.userAgent.indexOf("Netscape") != -1)
    {
    window.location = "http://www.i-code.co.uk";
    }
    else
    {
    window.location = "http://www.i-code.co.uk";
    }
    </script>
    </html>
     
    warman2442, Jun 4, 2008 IP
  2. bhutz

    bhutz Peon

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have a read of this page...http://developer.yahoo.com/yui/examples/yahoo/yahoo_ua_detection.html

    If it was up to me I would include the YUI library like so...
    <script type="text/javascript" src="http://yui.yahooapis.com/2.5.2/build/yahoo/yahoo-min.js"></script>
    HTML:
    and then use the example that's given...
    if (YAHOO.env.ua.gecko > 0) {}  // e.g. Firefox
    if (YAHOO.env.ua.ie > 0) {}     // Microsoft Internet Explorer
    
    // Or leverage boolean coercion -- 0 evaulates as false
    if (YAHOO.env.ua.opera) {}  // Opera
    if (YAHOO.env.ua.webkit) {} // Safari, Webkit
    HTML:
    I'm not 100% sure what you mean by the quote you added? But you could use a switch statement that will allow your code to exit and skip to the end.

    Can I ask why you want to redirect based on the browser?
     
    bhutz, Jun 5, 2008 IP
  3. warman2442

    warman2442 Active Member

    Messages:
    1,779
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    98
    #3
    Im having it on a free web hosting site.

    I dont want to give a redirection to users with firefox, i just want them to *Pass* threw, you know what i mean?
     
    warman2442, Jun 5, 2008 IP