another IE WTF

mpeters on 2006-05-24T16:25:59

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:

  stuff;

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.

   

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 '{output} .= '';
    } else {
        $self->{output} .= '';
    }
}


DOCTYPE

jk2addict on 2006-05-24T16:57:41

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.