Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Should we change linking so that conditional comments for IE are not destroyed?

by demerphq (Chancellor)
on Nov 05, 2004 at 17:11 UTC ( #405555=pmdevtopic: print w/replies, xml ) Need Help??

I was looking into some CSS/HTML related issues today and came across a weird but apparently quite useful trick for working around IE related problems. IE supports something called "html conditional comments", like this:

One variant allows HTML to be embedded that is ONLY seen by IE. IE will magically uncomment the group if the conditional is true. The comment like construction causes non IE browsers to treat the whole thing as a normal comment.

<!--[if IE 5]> <p>This will only show on IE 5.</p> <![endif]-->

The second variant will NOT be rendered on IE browsers (IE will magically remove the block if the expression is true), but WILL be rendered on NON IE browsers:

<![if !IE 5]> <p>This will only show if NOT on IE 5.</p> <![endif]>

The problem obviously is that our square bracket linking mechanisms will b0rk this totally. As I think this could be a really useful way to work around a number of IE related oddities I think its worth seriously considering the changes required to NOT bork it.

Anyway, just thought i should bring it up.


Replies are listed 'Best First'.
Re: Should we change linking so that conditional comments for IE are not destroyed?
by hostyle (Scribe) on Nov 05, 2004 at 18:25 UTC

    While conditional comments can be handy when you're really really stuck, I don't like to rely on them - mostly because CSS best feature is seperating style from content, and conditional comments must be in the HTML. You can change the entire appearance of a site by editting one CSS file - but if you're using conditional CSS you may have to edit many HTML files. There are other methods of limiting CSS to IE.

    /* display for IE only */ * html .whatever { font-weight: 300; /* hide from IE mac \*/ color: #ff0000; /* */ }

    Most CSS problems between IE 5, 5.5 and 6 on windows are easily resolved. If you have a particular problem that needs solving, let me know

    -- update: to answer demerph --

    See 398203

      Well, an example off the top of my head is that id like to figure out a way to apply the following style only if the user has IE.

      p.nnt-p-title { width: 70%; } p.nnt-author { width: 28%; }

      This CSS exploits a bug in IE which makes the Recently Active Threads look a lot nicer (IMO). But instead of ignoring it Opera will do totally silly things (as Opera users view the site in quirks mode)


Re: Should we change linking so that conditional comments for IE are not destroyed? (planned)
by tye (Sage) on Nov 05, 2004 at 20:03 UTC

    It is on my list to not modify square brackets inside of HTML comments. There are several reasons to do this (allowing JavaScript in the Free Nodelet, for example). It will be done by parsing HTML and square brackets in a single pass.

    - tye        

      Cool, thats nice to hear. Now the thing is will the html scraper get excited about weird stuff like the second example? If yes can we solve that too? :-)


Re: Should we change linking so that conditional comments for IE are not destroyed?
by Joost (Canon) on Nov 05, 2004 at 20:19 UTC

    Please don't use ugly hacks like this. There is no telling which other browsers parse HTML comments incorrectly, also rendering the "IE specific" code. IMHO it is not all that difficult to get IE 5 and higher to work well enough with anything that standards compliant browsers work with.

    If you have any issues with IE, I'd be willing to take a stab at them. Send me a chatterbox msg if you want.

Re: Should we change linking so that conditional comments for IE are not destroyed?
by Zero_Flop (Pilgrim) on Nov 05, 2004 at 20:31 UTC
    Best use of this.
    <!--[if IE 5]> <p> If you can read this, proceed to +irefox/ and dl Firefox</p> <![endif]-->
    ;) ZF

    By the way, I posted this from work and the text did not show up until I put it in code tags. IE6 ;( work imposed
      And while we're at it,
      <p style="display: none"> <font color="red" size="+4">You should be using a browser that support +s CSS!</font><br> <a href="">Upgrade now.</a> </p>

        Mozilla isn't an *upgrade* if you're using a different browser. I absolutely HATE the term "upgrade" where used instead of "migrate". For the record, Mozilla does NOT have a non-graphical browser. Besides that, not supporting CSS is a right that browsers have and you are not to tell me what to use. A good website maker makes a site usable for any browser. And CSS makes that easy if used right, so stop complaining.

        Note that I have seen your ";-)", but needed to say this because it's the third time I see someone suggesting something like this today.

        Juerd # { site => '', plp_site => '', do_not_use => 'spamtrap' }

      It didnt work because the sites internal mechanism b0rked it. (Have a look at the source code). Hence the reason for this thread....


Re: IE's conditional comments
by ww (Archbishop) on Nov 05, 2004 at 18:30 UTC
    interesting idea.

    FWIW, tried with IE 6.x (changed IE element in the conditionals to "IE6") and Moz 1.7x. IE 6 honors the conditional comments; Moz renders the negative conditionals which return true.

    Speculating now but Moz behavior may be because it demands w3c standard comments, < followed by two hyphens for open_comment and two hyphens > for close_comment.

    (3.2.4) White space is not permitted between the markup declaration open delimiter("<!") and the comment open delimiter ("--"), but is permitted between the comment close delimiter ("--") and the markup declaration close delimiter (">"). A common error is to include a string of hyphens ("---") within a comment. Authors should avoid putting two or more adjacent hyphens inside comments.

    Would like to know more about which "IE oddities" lead to what thoughts about working around them. A link to a reference on the workings of the square bracket mechanism here would be nice to have, if permitted

Re: Should we change linking so that conditional comments for IE are not destroyed?
by bart (Canon) on Nov 12, 2004 at 01:46 UTC
    You don't really want conditional HTML, you want conditional CSS. There are other tricks to make CSS only work for MSIE, for example, see this for an example. According to that page, you can specify CSS style properties with a leading "_" prefix, and only MSIE will pick it up (coloured blue in the syntax highlighted HTML example). I haven't tried it, but it is worth a shot.

    Googling for CSS underscore hack, and following some links, I ended up on this page: The Underscore Hack.

Re: Should we change linking so that conditional comments for IE are not destroyed?
by ysth (Canon) on Nov 07, 2004 at 05:53 UTC
    Simple solution: in the square bracket mangling code, pass through [-b0rk-foo-protect] as literal [foo].

      I was thinking of having [[ become just [ and ]] become ] (despite the minor lack of backward compat). But then you have to be very careful to not filter anything twice.

      - tye        

        Sounds reasonable; there are 77+ nodes with titles starting [, but I think all of them have a ], so there's no way to link to them by name now anyway.

Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2021-01-17 03:58 GMT
Find Nodes?
    Voting Booth?