Browser Specific Redirect

Discussion in 'HTML & Website Design' started by alecrust, Sep 1, 2007.

  1. #1
    Hello,

    I am looking for the best way to redirect the user to a different site, if they are using a version of Internet Explorer under 7.

    What would be the best way to do this?

    Thanks
     
    alecrust, Sep 1, 2007 IP
  2. NoobieDoobieDo

    NoobieDoobieDo Peon

    Messages:
    1,456
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use internet explorer conditional statements like
    <--[if ie7]-->
    code
    <--endif-->

    or some crap

    only IE can read this code, everything else thinks it's a comment and ignores it

    do a google and MS will tell you more
     
    NoobieDoobieDo, Sep 1, 2007 IP
  3. HypertextFever

    HypertextFever Peon

    Messages:
    158
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah, the IE conditional comments work best, but then you have to use a client-side redirect... Oh well :)

    Here's your code:

    <!--[if lt IE 7]>
    <script type="text/javascript">
    window.location = "http://www.your-redirect-url.com";
    </script>
    <p>If you are not automatically redirected, please <a href="http://www.your-redirect-url.com">click here</a>.</p>
    <![endif]-->
    
    Code (markup):
     
    HypertextFever, Sep 1, 2007 IP
  4. alecrust

    alecrust Member

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    Many thanks for that!

    I was wondering, which is better, that JavaScrip or this PHP:
    
    $vernum=array();
    
    $regex = '/MSIE ([0-9]+)\..+;/';
    
    preg_match($regex,$_SERVER['HTTP_USER_AGENT'],$ver);
    
    if (count($ver) < 2)
    {
        // not IE at all
    }
    else
    {   
        // IE
        if ($ver[1] < 7)
        {
            // version < 7 so redirect
            header('Location: http://www.example.com/');
            exit;   
        }
        else
        {
            // version >= 7
        }
    }
    
    Code (markup):
    Thanks again
     
    alecrust, Sep 1, 2007 IP
  5. Mooseman

    Mooseman Peon

    Messages:
    453
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    PHP would be a better option, since some people might have javascript turned off.

    I'm not sure wether you can turn it off in IE though since I'm not using it.. ? :S
     
    Mooseman, Sep 1, 2007 IP
  6. HypertextFever

    HypertextFever Peon

    Messages:
    158
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    PHP always wins over javascript for redirects. :)
     
    HypertextFever, Sep 3, 2007 IP
  7. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #7
    And .Net trumps all ;)

    Javascript is limited to those that have javascript turned on but this is the vast majority - be careful of stats that you find on this as bots/ spiders typically dont support javascript and so will skew the numbers as the true figure you want for this project is the number of IE7 users with javascript enabled.

    As per the previous query you posted on this though, look at the reason as to why you are redirecting. If it is to fix layout issues then it is much better to actually fix the base problem than trying to maintain 2 versions of a site (or at worst dynamically set the layout template by browser rather than redirect to a duplicate of the site)
     
    AstarothSolutions, Sep 3, 2007 IP
  8. HypertextFever

    HypertextFever Peon

    Messages:
    158
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You just HAD to go there, didn't you! :rolleyes:

    (Open Source > * .NET)
     
    HypertextFever, Sep 4, 2007 IP
  9. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #9
    First off, and don't take offense at what I'm about to say, if you need to direct an IE user who's not using Internet Explorer 7 to a different page, you're doing something wrong.

    Now that that's out of the way, what does your "problem page" look like (I'm asking because I'm fairly certain you have one)?
     
    Dan Schulz, Sep 5, 2007 IP
  10. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #10
    Agreed - most likely. Browser sniffing on that level usually indicates some layout element or other feature which pretty much means you are doing something wrong in the first place.

    What he said.
     
    deathshadow, Sep 5, 2007 IP
  11. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Not necessarily, it could be a "want to" rather than "need to" - could be page 1 slags IE 7 off calling anyone who has installed it idiots and page 2 says how great IE 7 is and how the world is now your oyster and they only want people to see the relevant message (unlikely but you get the principle)

    As per my post though, agree if it is a layout issue then the problem should be fixed and not a redirect used.
     
    AstarothSolutions, Sep 5, 2007 IP
  12. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #12
    In which case you're doing something wrong - and that's by starting with what you want people to use, not what they want to use. Respect the user's preference - or predicament, and give them the content they were seeking in the first place.
     
    Dan Schulz, Sep 5, 2007 IP