Adding IE Conditional Comments in WO

Or how to keep WO and IE happy

Developing web applications with WebObjects is great fun. Developing web applications with HTML and CSS is great fun too. Until it is time to pay the Win/IE-tax — the extra 10-20% on top of each project to persuade that particular browser to play nicely with standard-compliant code.

Rather than working with CSS hacks, we prefer to stuff all the Win/IE rules in a separate stylesheet and use the IE Conditional Comment to get IE to pick it up. Normally this involves putting something like this in the head section of the html page:

<!--[if lt IE 7]><link rel="stylesheet" href="/_resources/styles/pm_default_ie_fixes.css" type="text/css" /><![endif]-->

But this type of comment gets rather mangled in WOBuilder. The trick there is to use a WOGenericElement instead:

IEStyles:WOGenericElement { 
elementName ="!--[if lt IE 7]><link rel=\"stylesheet\" href=\"/_resources/styles/pm_default_ie_fixes.css\" type=\"text/css\" /><![endif]--"; 
}

It relies on the WOGenericElement supplying the opening and closing angle-brackets, and being happy to put this rather long and strange looking element name inside them.

And as a special bonus, to put an IE Conditional Comment into an XML file through the magic of XSLT, use something like this:

<xsl:comment><![CDATA[[if lt IE 7]><link rel="stylesheet" href="/_resources/styles/pm_default_ie_fixes.css" type="text/css" /><![endif]]]></xsl:comment>

Maybe one day a certain browser will be compatible with standards and we can all avoid having to write separate stylesheets to keep it happy, but until then this has been a useful way for us to keep everyone happy, whether we’re writing static HTML, WebObjects applications, or XSLT transforms.

Post your own comment here:











Note: be friendly! We reserve the right to moderate inappropriate, offensive, or wildly off-topic comments. Your email address is required, but won't be displayed. All comments are moderated, so don’t expect them to show up instantly.