1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Browser Based Redirects

Discussion in 'JavaScript' started by BCRed, Aug 2, 2010.

  1. #1
    Hey everyone. Had a quick question hopefully someone here can help me out with. I'm trying to figure out how to get a link to redirect users depending on their broswer. (The offer I'm working with doesn't work with Internet Explorer 8). Basically I want all IE8 traffic to go to one page, and all other traffic to another. I've been looking around and here's the best I've found so far:

    <?
    //if its MSIE then
    if ($name = strstr ($HTTP_USER_AGENT, "MSIE"))
    {
    //go to Index.php
    Header ("Location: index.php");
    }
    else
    {
    //else go to BrowserUpdate
    Header ("Location: browser_options.php");
    }
    ?>

    What would I have to change to get it to isolate IE8 as I don't want to redirect any more users than I absolutely have to, and also, will the above script work.

    Thanks in advance for any help
     
    BCRed, Aug 2, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    That looks like a PHP code. It should be something like this:
    
    <?php
    if (preg_match("/MSIE 8/", $_SERVER['HTTP_USER_AGENT'])) header("Location: index.php");
    else header("Location: browser_options.php");
    ?>
    
    PHP:
     
    Rainulf, Aug 2, 2010 IP
    BCRed likes this.
  3. XoC

    XoC Active Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Since this is in the javascript section I'll add you an alternative..

    
       <script langauge="javascript">
       function checkIE()
       {
          var ua = window.navigator.userAgent
          var ie = ua.indexOf ("MSIE ")
    
          if (ie >= 8) 
             window.location = "http://www.example.com";
          else                 
             return 0
       }
       </script>
       <body onload="checkIE();">
    
    Code (markup):
     
    XoC, Aug 3, 2010 IP
    BCRed likes this.
  4. BCRed

    BCRed Active Member

    Messages:
    249
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #4
    Thanks to both of you for the help. I really appreciate it. As a bit of a follow up is there any advantage to using PHP or Javascript to do this or does it not really matter?
     
    BCRed, Aug 3, 2010 IP
  5. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Far better to avoid JavaScript unless necessary, as it is possible that the user does not have it enabled (only a very small percentage). You are probably better off inserting your code into 'index.php', doing nothing if the browser is I.E, and redirecting if it isn't. This will mean that only users that aren't using MSIE will then be redirected. I don't use php but probably something like:
    
    <?php
    if (preg_match("/MSIE /", $_SERVER['HTTP_USER_AGENT']) == 0) header("Location: browser_options.php");
    ?>
    ... Your msie index.php would go here ...
    
    Code (markup):
    Why is it that you need a different website for each browser? Cross browser development is a pain, but can be done if taken the time.
     
    camjohnson95, Aug 3, 2010 IP
    BCRed likes this.
  6. BCRed

    BCRed Active Member

    Messages:
    249
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #6
    Thanks. I'll take your advice and go with PHP on this one.

    The issue for me is it's not my site that's causing the problem. It's an affiliate offer, and sadly, their website sets off all sorts of security and browser alerts in IE8, which basically kills it since the website in question is an online shopping cart. I'll be finding a better solution in the long run but in the short term redirecting IE8 to a similar but slightly poorer site is my best way of dealing with it
     
    BCRed, Aug 3, 2010 IP