Sign In/My Account | View Cart  
advertisement

Article:
 The Vanishing Image: XHTML 2 Migration Issues
Subject: Use of Conditional Comments
Date: 2003-07-03 21:30:26
From: MikeyC Cacciottolo

Using conditional comments as described in the article will actually hide the nested Object from all browsers:


<!--[if !IE]>
<object></object>
<![endif]-->


Therefore, it should be constructed in the following way in order to hide the nested Object only from Internet Explorer. However, this method won't validate which means it can't be used in XHTML 2.0:


<![if !IE]>
<object></object>
<![endif]>


No Previous Message Previous Message   Next Message Next Message


Titles Only Titles Only Oldest First
  • Use of Conditional Comments
    2003-07-04 00:38:36 bryan rasmussen [Reply]

    conditional comments has always seemed sort of an ugly hack to me, although if the focus starts to shift from IE as the development target of choice to IE as a legacy browser then they become perhaps more useful.

    • Use of Conditional Comments
      2003-07-05 06:58:33 James Fuller [Reply]

      +1 on that, and why build another processing idiom, when we have xslt;


      legacy html


      <html>
      <body>
      <img id="1" src="sample.jpg" alt="sample" width="100" height="100" />
      </body>
      </html>


      migration stylesheet
      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" version="1.0"/>


      <xsl:template match="/">
      <xsl:apply-templates/>
      </xsl:template>


      <xsl:template match="img">
      <object id="{@id}"
      type="image/jpeg"
      data="{@src}"
      width="{@width}"
      height="{@height}"/>
      </xsl:template>
      </xsl:stylesheet>


      and of course we can build in logic to manipulate as per the "if" statements.


      Personally, I see xhtml a perfect partner with xslt, and would like to see increased binding between the two.


      cheers, jim fuller

  • Use of Conditional Comments
    2003-07-04 03:17:18 Florian Bauer [Reply]

    You can embed the conditional comments like this:
    <!-- [if !IE] -->
    <object></object>
    <!-- <![endif] -->


    • Use of Conditional Comments
      2003-07-04 07:46:18 MikeyC Cacciottolo [Reply]

      "You can embed the conditional comments like this:
      <!-- [if !IE] -->
      <object></object>
      <!-- <![endif] -->"


      Your example doesn't work. You can't use conditional comments in that manner.


      • Use of Conditional Comments
        2003-07-04 14:37:27 Florian Bauer [Reply]

        I double-checked my example. It does indeed work, at least with the german version of IE 6. I have no idea whether this hack will work with any other version of IE. What version of IE did you use for testing?

        • Use of Conditional Comments
          2003-07-04 20:50:34 MikeyC Cacciottolo [Reply]

          IE6 sp1 - english running on Windows NT &
          IE6 sp1 - english running on Windows XP


          Here is the exact example I used (and I just double-checked it):


          <!-- [if !IE] -->
          i can see this in Internet Explorer
          <!-- <![endif] -->


          • Use of Conditional Comments
            2003-07-05 04:38:08 Florian Bauer [Reply]

            That is strange:
            Here is my example:


            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
            <head>
            </head>
            <body>


            <!--[if !IE]> -->
            IE doesn't see this.
            <!-- <![endif] -->


            </body>
            </html>


            I checked this with ie6 on winxp, and ie5.5 on win98, both in the german version.
            I also tried your example and the conditional comments do also work there.
            strange...
            cheers
            Florian

            • Use of Conditional Comments
              2003-07-05 11:25:34 MikeyC Cacciottolo [Reply]

              I've isolated the problem. Your original example was:
              <!-- [if !IE] -->
              <object></object>
              <!-- <![endif] -->


              Your follow-up example was (notice there is no space before the opening bracket of the if statement):


              <!--[if !IE] -->
              <object></object>
              <!-- <![endif] -->


              Your second example is indeed correct. Why do trhings have to be so confusing ;)

            • Use of Conditional Comments
              2003-07-06 16:17:35 MikeyC Cacciottolo [Reply]

              I just realized something else. The example we've been playing with thus far uses a transitional doctype as it doesn't validate using a strict doctype. Something about character data not being allowed there according to the validator.


              XHTML 2 won't have a transitional mode (as far as I'm aware), so it seems that you can't use conditional comments anyways to deal with IE's broken Object support.


              Please correct me if I'm wrong.

              • Re: Use of Conditional Comments
                2003-10-16 18:09:25 Lenny D [Reply]

                "I just realized something else. The example we've been playing with thus far uses a transitional doctype as it doesn't validate using a strict doctype. Something about character data not being allowed there according to the validator."


                XHTML does not allow character data at the <body> level. It must be within a block level element such as

                .



  • Use of Conditional Comments
    2006-04-09 08:19:33 allthegoodnamesaretaken [Reply]

    I can't comment on xhtml but I've tested all the examples above as plain HTML and they don't work! However there is a syntax for 'down-level' (Microsofts' obnoxious label for browsers that aren't IE) CC's that works AND validates:


    <!--[if gte IE 6]><!-->
    Seen by all real browsers and IE 6. Validates as HTML 4.01 Transitional and possibly other doctypes
    <!--<![endif]-->


    Tested and working on Firefox 1.5, Opera 7.5, IE6, Konqueror and Lynx.


    The only problem I've found with this code is that it confuses the syntax highlighter built into the CFML module for Eclipse (causing it to render the remaining page in comment green).


    Thanks to Stu at cssplay.co.uk for finding this. I don't know where he found it but I'm grateful anyway. As usual the MS documentation was completely useless and even google failed to turn up much of value.


Sponsored By: