SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast whitecreek's Avatar
    Join Date
    Aug 2011
    Location
    Madrid, Spain
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Redirecting, hope this is a simple one...

    Good afternoon,

    I'm trying to redirect a web page into a different one in case someone gets to it using IE6. I'm a real beginner in js and I found this through google:

    Code JavaScript:
    <script >
     
    if (navigator.appName=="Microsoft Internet Explorer"){
     
       location.href="http://www.redirect.html";
    }
    </script>

    It seems to work ok for MSIE. ┐Any simple way to make it specific for IE6 only?

    Any help would be appreciated. Thanks a lot in advance...

  2. #2
    SitePoint Member
    Join Date
    Dec 2010
    Location
    Southeast Michigan
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to check for a specific version use the .appVersion method like this:

    Code JavaScript:
    if (navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion == "6.0 (Windows)") {
     
       location.href="http://www.redirect.html";
    }

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by whitecreek View Post
    It seems to work ok for MSIE. ┐Any simple way to make it specific for IE6 only?
    Microsoft has something called conditional comments that are used for such a task. It's much more reliable than sniffing the app name and version, as those can be easily faked.

    Conditional comments are ignored by all other web browsers, and only obeyed by Internet Explorer.

    Here's how a conditional comment would work, where you're checking if the IE version is less than or equal to 6:

    Code:
    <!--[if IE lte 6]>
    <meta http-equiv="refresh" content="0; url=http://www.redirect.html/">
    <![endif]-->
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Enthusiast whitecreek's Avatar
    Join Date
    Aug 2011
    Location
    Madrid, Spain
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's great stuff Paul.

    I knew about the conditional comments in order to lead to different CSS files depending on the IE version the user is using, but I didn't know they could be used for redirecting purposes. It really simplifies the problem. Excellent article the one included in your post on Conditional comments

    Thanks a lot for the tip.

    @ emiljan, thanks very much for the information.

    Regards.

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,258
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    .....
    It's much more reliable than sniffing the app name and version, as those can be easily faked.
    .....
    And no reliance on javascript being enabled

  6. #6
    SitePoint Enthusiast whitecreek's Avatar
    Join Date
    Aug 2011
    Location
    Madrid, Spain
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aaaaand... the conditional comment trick is not really working. May be there's something I'm not doing right.

    Here is the comment I used:

    HTML Code:
    <!--[if IE lt 7]><meta http-equiv="refresh" content="0; url=http://www.ficoprieto.com/tartaruga/index.html/"><![endif]-->
    I took it this should be placed within the <head>, like the rest of conditional comments, and I placed it just after the <head> opening tag, right before the charset META tag, so it would be the first line read after the DOCTYPE statement.

    ┐is it necessary for this specific conditional comment to be placed anywhere else?

    Thanks in advance.

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by whitecreek View Post
    Aaaaand... the conditional comment trick is not really working. May be there's something I'm not doing right.
    What is "not really working" with it?

    • Does it fail to do anything?
    • Does it redirect all web browsers regardless of being Internet Explorer or not?
    • Does it only redirect in Internet Explorer but ignore the version?
    • Does it change the screen color to duck-egg blue?
    • Does it cause your computer to crash?
    • Does it make your dog bury your slippers in the garden?
    • Does your computer ask you "Shall we play a game?"
    • Does the dog ask you "Shall we play a game?"


    What is it?

    If you have trouble diagnosing such things, let's us check it out. Where is a test page where you have it, for the sake of testing purposes.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Enthusiast whitecreek's Avatar
    Join Date
    Aug 2011
    Location
    Madrid, Spain
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    I'll never let my dog handle my slippers!!

    Well, it's not working meaning that it's not doing what it was expected for it to do, that is, redirecting to a different page. You could say it fails to do anything.

    I ended up using a piece of js (it was my second best bet) that seems to be working fine, since I was in a bit of a hurry (my client was starting to despair).

    I found the js piece of code here: JS REDIRECT CODE

    And here is the URL for the website, not officialy "on the air" yet since there's still a couple of things left to do.

    I┤d be interested anyway in a way of sorting the conditional comment thing, if you have the time. I like it a lot better as a solution for redirecting after detecting the IE version. As I said, I placed it right after the opening <head> tag.

    Here is the comment again:

    HTML Code:
    <!--[if IE lt 7]>
    <meta http-equiv="refresh" content="0;url=http://www.ficoprieto.com/tartaruga/index.html">
    <![endif]-->
    Thanks again.

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by whitecreek View Post


    I'll never let my dog handle my slippers!!
    Let's get them back for you.

    The syntax here is incorrect:

    Code:
    <!--[if IE lt 7]>
    The lt should come before the IE

    Code:
    <!--[if lt IE 7]>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #10
    SitePoint Enthusiast whitecreek's Avatar
    Join Date
    Aug 2011
    Location
    Madrid, Spain
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, that was it, I got my slippers back

    It worked just fine.

    Thanks a million!!


Tags for this Thread

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
  •