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:

<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…

to check for a specific version use the .appVersion method like this:


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

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:


<!--[if IE lte 6]>
<meta http-equiv="refresh" content="0; url=http://www.redirect.html/">
<![endif]-->

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.

And no reliance on javascript being enabled :slight_smile:

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:

<!--[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.

What is “not really working” with it?

[list][]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?”[/list]

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.

:lol:

I’ll never let my dog handle my slippers!! :slight_smile:

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:

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

Thanks again.

Let’s get them back for you.

The syntax here is incorrect:

<!--[if IE lt 7]>

The lt should come before the IE

<!--[if lt IE 7]>

Yep, that was it, I got my slippers back :slight_smile:

It worked just fine.

Thanks a million!!