Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
-6
rated 0 times [  0] [ 6]  / answers: 1 / hits: 39520  / 15 Years ago, fri, april 10, 2009, 12:00:00

I'm trying to find a way to display one link to an IE user and another link to all other browsers using javascript or conditional comments (or whatever it takes).



Basically...



//pseudo code
<!--[if IE]>
<a hrefie-only.html>click here!</a>
<!--[else]>
<a hrefall-other-browsers.html>click here!</a>
<![endif]-->


I don't think this is possible with conditional comment tags (which only work in internet explorer). Plus I don't think there is an else statement.



Is there a way to do this with javascript? Please help! Thanks!


More From » html

 Answers
73

I don't think this is possible with conditional comment tags (which only work in internet explorer)




Sure it is. You just have to leave the content for non-IE browsers in a position such that it's part of a conditional comment clause but not actually inside a <!-- comment -->. Then browsers that don't know about conditional comments will see the content fine. This is known as a downlevel-revealed conditional comment.



Unfortunately the markup Microsoft give you there is invalid HTML (and not even well-formed XML). To make it pass muster you just need a few additional ‘--’s:



<!--[if IE]> This is IE! <![endif]-->
<!--[if !IE]><!--> This ain't IE! <!--<![endif]-->


Although I have to echo AnonJr's non-answer, in that it's rare you should need a completely separate link/page for IE compared to other browsers. If you're doing something tricky like complex VML and ActiveX work in IE with Flash on other browsers I guess there could be a reason for it, but usually a few CSS and script hacks over the same basic page should suffice.


[#99720] Friday, April 3, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
savanar

Total Points: 237
Total Questions: 105
Total Answers: 99

Location: Wales
Member since Mon, May 17, 2021
3 Years ago
;