Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

mpeters (5802)

mpeters
  (email not shown publicly)
http://petersfamily.org/
AOL IM: michael00peters (Add Buddy, Send Message)

Technorati Profile [technorati.com]

Journal of mpeters (5802)

Wednesday May 24, 2006
11:25 AM

another IE WTF

[ #29696 ]

How many of you have heard of "downlevel-revealed conditional comments" in HTML. Of course you haven't. It's something that Microsoft made up. They look like this:

  <![if IE]>stuff<![endif]>;

This means that stuff will only show up in IE browsers < 5.0.

It's bad enough that they have "downlevel-hidden conditional comments", but at least those look like normal comments.

   <!--[if !IE gte 6]>stuff<![endif]-->

This means that stuff will only show up in IE 6+. While this is a great way for MS to increase their market share by encouraging markup that only works in IE, at least it doesn't break anything in other browsers since it actually is a valid comment.

Why does this matter? I'm currently working on a $project where the audience can be using some pretty crufty browsers. We want to provide some eye-candy to those with modern browsers and just prevent those with broken browsers from getting all those annoying JS pop-up boxes with errors. The designer decides to use "downlevel-hidden conditional comments" to hide it from IE 5 and IE(mac). This works ok until we notice that on pages with forms it's broken. That's because we were using HTML::FillInForm (one of my favorite modules) which is based on HTML::Parser. HTML::Parser is smart enough to recognize those funny IE comments as comments, which is helpful. However, it does not treat them any differently than any other comments. So when HTML::FillInForm is creating the final document, it reads in a comment and then outputs a comment. Sounds like the right thing to do, except this breaks those funny IE comments because they now come out looking like normal comments.

The solution? I hacked up a quick sublcass of HTML::FillInForm for the project that will do-the-right thing when it encounters those little suckers. All I had to do was override the comment sub. So in case anyone else needs to use it, here it is:

sub comment {
    my ( $self, $text ) = @_;
    # if it begins with '[if ' and doesn't end with '<![endif]'
    # it's a "downlevel-revealed" conditional comment (stupid IE)
    # or
    # if it ends with '[endif]' then it's the end of a
    # "downlevel-revealed" conditional comment (stupid IE)
    if(
        (
            ( index($text, '[if ') == 0 )
            &&
            ( $text !~ /<!\[endif\]$/ )
        )
        ||
        ( $text eq '[endif]' )
    ) {
        $self->{output} .= '<!' . $text . '>';
    } else {
        $self->{output} .= '<!--' . $text . '-->';
    }
}

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • It looks like this fix would help with ENTITY and other declarations in pages with custom DTD info at the top.

    I would definitely submit a patch to RT for this fix.