Conditional comments: is this new?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Benjamin Niemann

    Conditional comments: is this new?

    Hello,

    I've been just investigating IE conditional comments - hiding things from
    non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide
    code from IE/Win browsers.
    I found <![if ..]> in the original MSDN documentation, but this is (although
    it is working) unfortunately non-validating gibberish.
    So I fooled around trying to find a way to make it valid. And voila:

    <!--[if IE]><![if !IE]><![endif]-->
    <p>IE/Win ignores this</p>
    <!--[if IE]><![endif]><![endif]-->

    Seems like IE has some very strange nesting rules that make a programmers
    heart scream in agony...

    Did I found something new, or is this common knowledge?

    A complete test page can be found at:

    (warning: DSL connected host with dynamic IP, might be offline once in a
    while)

    Greetings to you all!

    --
    Benjamin Niemann
    Email: pink at odahoda dot de
    WWW: http://www.odahoda.de/
  • Lachlan Hunt

    #2
    Re: Conditional comments: is this new?

    Benjamin Niemann wrote:[color=blue]
    > I've been just investigating IE conditional comments - hiding things from
    > non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide
    > code from IE/Win browsers.[/color]

    Conditional comments are evil for the same reasons that browser sniffing
    is evil. See this thread on www-style which has just been discussing
    this very issue.


    In particular, my post sums up why conditional comments should not be
    used, but there's a lot more useful information from other people
    elsewhere in the thread too.

    [color=blue]
    > I found <![if ..]> in the original MSDN documentation, but this is (although
    > it is working) unfortunately non-validating gibberish.[/color]

    Other than browser sniffing, this is the other reason why conditional
    comments are evil, as discussed in bugzilla
    VERIFIED (harishd) in Core - DOM: HTML Parser. Last updated 2007-09-29.

    [color=blue]
    > So I fooled around trying to find a way to make it valid. And voila:
    >
    > <!--[if IE]><![if !IE]><![endif]-->
    > <p>IE/Win ignores this</p>
    > <!--[if IE]><![endif]><![endif]-->[/color]

    That's a clever way to get around it, but it's still evil. Why do you
    want to hide some content from IE, but not other browsers?
    [color=blue]
    > Seems like IE has some very strange nesting rules that make a programmers
    > heart scream in agony...[/color]

    IE has some very strange behaviour that makes all developer's hearts
    scream in agony...
    [color=blue]
    > Did I found something new, or is this common knowledge?[/color]

    Conditional comments have been around since IE 5, as described in the
    documentation, so why would they be new?

    --
    Lachlan Hunt

    http://GetFirefox.com/ Rediscover the Web
    http://GetThunderbird.com/ Reclaim your Inbox

    Comment

    • Benjamin Niemann

      #3
      Re: Conditional comments: is this new?

      Lachlan Hunt wrote:
      [color=blue]
      > Benjamin Niemann wrote:[color=green]
      >> I've been just investigating IE conditional comments - hiding things from
      >> non-IE/Win browsers is easy, but I wanted to know, if it's possible to
      >> hide code from IE/Win browsers.[/color]
      >
      > Conditional comments are evil for the same reasons that browser sniffing
      > is evil. See this thread on www-style which has just been discussing
      > this very issue.
      > http://lists.w3.org/Archives/Public/.../thread.html#6
      >
      > In particular, my post sums up why conditional comments should not be
      > used, but there's a lot more useful information from other people
      > elsewhere in the thread too.
      > http://lists.w3.org/Archives/Public/...5Apr/0072.html[/color]
      mmm.. I would consider hacks like

      * html div { margin: 20%; }

      as being more evil than conditional comments, because it exploits a bug in
      IE that might be fixed at any time by MS (whereas the other bugs that you
      want to work around with such constructs may remain).

      But my intention was not to discuss the evilness of such things - this has
      obviously already been done elsewhere.
      Thanks for the references. I will have a deeper look at them later.
      [color=blue]
      > [snip][/color]
      [color=blue][color=green]
      >> So I fooled around trying to find a way to make it valid. And voila:
      >>
      >> <!--[if IE]><![if !IE]><![endif]-->
      >> <p>IE/Win ignores this</p>
      >> <!--[if IE]><![endif]><![endif]-->[/color]
      >
      > That's a clever way to get around it, but it's still evil. Why do you
      > want to hide some content from IE, but not other browsers?[/color]
      Nothing particular at the moment. But sometimes conditional comments are
      useful (IMHO).
      [color=blue]
      > [snip][/color]
      [color=blue][color=green]
      >> Did I found something new, or is this common knowledge?[/color]
      >
      > Conditional comments have been around since IE 5, as described in the
      > documentation, so why would they be new?[/color]
      I wanted to know, if my 'clever way to get around it' is new in the meaning
      of 'not yet discovered'.

      Ciao

      --
      Benjamin Niemann
      Email: pink at odahoda dot de
      WWW: http://www.odahoda.de/

      Comment

      • Lachlan Hunt

        #4
        Re: Conditional comments: is this new?

        Benjamin Niemann wrote:[color=blue]
        > Lachlan Hunt wrote:
        >
        >[color=green]
        >>Benjamin Niemann wrote:
        >>[color=darkred]
        >>>I've been just investigating IE conditional comments - hiding things from
        >>>non-IE/Win browsers is easy, but I wanted to know, if it's possible to
        >>>hide code from IE/Win browsers.[/color]
        >>
        >>Conditional comments are evil for the same reasons that browser sniffing
        >>is evil. See this thread on www-style which has just been discussing
        >>this very issue.
        >>http://lists.w3.org/Archives/Public/.../thread.html#6
        >>
        >>In particular, my post sums up why conditional comments should not be
        >>used, but there's a lot more useful information from other people
        >>elsewhere in the thread too.
        >>http://lists.w3.org/Archives/Public/...5Apr/0072.html[/color]
        >
        > mmm.. I would consider hacks like
        >
        > * html div { margin: 20%; }
        >
        > as being more evil than conditional comments[/color]

        CSS hacks are evil too, but their not as evil as conditional comments
        because:
        * They don't depend on the UA identification.
        * When a browser vendor releases a new version that fixes the bugs that
        allow the hack and the bugs that require the hack in the first place,
        the new version will automatically work like other standards compliant
        browsers.
        * For conditional comments that test the version number:
        - When a new version is released, the author needs to check whether or
        not the conditional comment should still apply, and update the
        version number as required.
        * For conditional comments that don't test the version number:
        - When a new version is released, the author needs to check whether or
        not the conditional comment should still apply, and add a version
        number so the new version doesn't apply the hack if necessary.
        * Conditional comments are nested within the document markup, where each
        and every occurance needs to be updated, whereas CSS hacks can be
        managed in a single external file.

        All forms of hacks inlcuding CSS hacks, conditional comments, javascript
        hacks, or whatever should be used sparingly, and browser sniffing should
        never be done without an exceptionally good reason.

        So far, the *only* possibly acceptable use of a conditional comment I've
        seen is for Dean Edward's IE7 script, so that other browsers won't
        bother downloading a script they don't need.

        Ideally hacks should be used only where absolutely necessary to maintain
        accessibility and graceful degredation. Using them to achieve pixel
        perfection should generally be avoided, IMHO.
        [color=blue]
        > because it exploits a bug in IE that might be fixed at any time by MS[/color]

        And when it is fixed, the hack should no longer apply! So what's the
        problem?
        [color=blue]
        > (whereas the other bugs that you want to work around with such
        > constructs may remain).[/color]

        There's not as much wrong with exploiting a bug to work around another,
        as there is with techniques that assume a single user agent will always
        have a bug, or that a bug is associated with particular version numbers.
        Although both kinds of techniqes are evil, one is less evil than the
        other.
        [color=blue]
        > Nothing particular at the moment. But sometimes conditional comments are
        > useful (IMHO).[/color]

        I don't want to get involved in another argument about their evilness vs
        their usefulness, so no further comment.
        [color=blue][color=green][color=darkred]
        >>>Did I found something new, or is this common knowledge?[/color]
        >>
        >>Conditional comments have been around since IE 5, as described in the
        >>documentation , so why would they be new?[/color]
        >
        > I wanted to know, if my 'clever way to get around it' is new in the meaning
        > of 'not yet discovered'.[/color]

        Well, in that case, I've never seen that particular technique before.

        --
        Lachlan Hunt

        http://GetFirefox.com/ Rediscover the Web
        http://GetThunderbird.com/ Reclaim your Inbox

        Comment

        • Spartanicus

          #5
          Re: Conditional comments: is this new?

          Lachlan Hunt <spam.my.gspot@ gmail.com> wrote:
          [color=blue]
          >Conditional comments are evil for the same reasons that browser sniffing
          >is evil. See this thread on www-style which has just been discussing
          >this very issue.
          >http://lists.w3.org/Archives/Public/.../thread.html#6[/color]

          IIRC that discussion is mainly about the desirability of having CCs for
          browsers other than IE, which would likely be misunderstood and misused
          by many.

          Currently only NS4 and IE5+ have implemented CCs (in a different way),
          and there's no evidence that other browser developers are likely to
          implement them.

          Microsoft's "Uplevel revealed" (cringe on the name) CC's are a 100%
          reliable way to feed additional code to IE. The same cannot be said for
          "css hacks".

          IE's CCs are predominantly used by authors who want to feed good quality
          browsers proper code, and feed something propriety or sub standard to
          IE.

          Microsoft "Downlevel revealed" CCs are a different matter, they cause
          validation errors.

          --
          Spartanicus

          Comment

          • Lachlan Hunt

            #6
            Re: Conditional comments: is this new?

            Spartanicus wrote:[color=blue]
            > Currently only NS4 and IE5+ have implemented CCs[/color]

            How did NS4 conditional comments work? I've never heard of them before.
            [color=blue]
            > Microsoft's "Uplevel revealed" (cringe on the name)[/color]

            do you mean "downlevel-hidden"?
            [color=blue]
            > Microsoft "Downlevel revealed" CCs are a different matter, they cause
            > validation errors.[/color]

            <!--[if IE]>downlevel-hidden conditional comments can cause
            validation -- errors too<![endif]--> and their
            comment parsing implementation is broken, even
            in standards compliance mode -->

            --
            Lachlan Hunt

            http://GetFirefox.com/ Rediscover the Web
            http://GetThunderbird.com/ Reclaim your Inbox

            Comment

            • Alan J. Flavell

              #7
              Re: Conditional comments: is this new?

              On Thu, 7 Apr 2005, Lachlan Hunt wrote:
              [color=blue]
              > Conditional comments are evil for the same reasons that browser
              > sniffing is evil.[/color]

              I'm not sure that I could agree with that as written.

              Conditional comments are evaluated by the browser itself. You /know/
              what it's going to do on browsers which are not addressed by it (since
              they take the form of HTML comments and will be parsed as such; of
              course I would disain to use the other MS variant which causes syntax
              validation errors).

              "Browser sniffing" mostly turns out to rely on server-side parsing of
              user agent strings (that's how the participants seem to be
              interpreting it on your cited www-style thread), and that's subject to
              a whole catalogue of objections on both practical and theoretical
              grounds.
              [color=blue]
              > See this thread on www-style which has just been discussing this
              > very issue.
              > http://lists.w3.org/Archives/Public/.../thread.html#6[/color]

              The other deployed technique, as you know, is to capitalise on known
              bugs in particular browser/versions - for example to persuade a
              particular browser to ignore some stuff that it doesn't properly
              support, as discussed in


              But that too is potentially unreliable, since browser developers might
              fix one bug without fixing the other(s).
              [color=blue][color=green]
              > > I found <![if ..]> in the original MSDN documentation, but this is
              > > (although it is working) unfortunately non-validating gibberish.[/color][/color]

              If it doesn't validate, then it can't be said in any real sense to be
              working. Even if it does what its misguided inventor intended, it
              still isn't "working" in any real WWW-compatible sense.

              Well, my objection to IE conditional comments is not that they don't
              work reliably, but that they merely confirm the belief that IE is not
              a WWW-compatible browser and should not be used as one. And then
              there's no further need for this anti-WWW technique. But
              unfortunately there's a whole mass of users out there who haven't got
              - and presumably won't be likely to get - that message.
              [color=blue]
              > IE has some very strange behaviour that makes all developer's hearts
              > scream in agony...[/color]

              Amen to that.

              Comment

              • Spartanicus

                #8
                Re: Conditional comments: is this new?

                Lachlan Hunt <spam.my.gspot@ gmail.com> wrote:
                [color=blue][color=green]
                >> Currently only NS4 and IE5+ have implemented CCs[/color]
                >
                >How did NS4 conditional comments work? I've never heard of them before.[/color]

                I'm sure SE's have.
                [color=blue][color=green]
                >> Microsoft's "Uplevel revealed" (cringe on the name)[/color]
                >
                >do you mean "downlevel-hidden"?[/color]

                Yes (they label IE5 as "Uplevel browser").
                [color=blue][color=green]
                >> Microsoft "Downlevel revealed" CCs are a different matter, they cause
                >> validation errors.[/color]
                >
                ><!--[if IE]>downlevel-hidden conditional comments can cause
                > validation -- errors too<![endif]--> and their
                > comment parsing implementation is broken, even
                > in standards compliance mode -->[/color]

                Not an argument against proper usage.

                --
                Spartanicus

                Comment

                • Spartanicus

                  #9
                  Re: Conditional comments: is this new?

                  Lachlan Hunt <spam.my.gspot@ gmail.com> wrote:
                  [color=blue][color=green]
                  >> mmm.. I would consider hacks like
                  >>
                  >> * html div { margin: 20%; }
                  >>
                  >> as being more evil than conditional comments[/color]
                  >
                  >CSS hacks are evil too, but their not as evil as conditional comments
                  >because:
                  >* They don't depend on the UA identification.[/color]

                  CSS parsing bugs are often shared amongst various browsers, so that's a
                  reason in *favour* of CCs.
                  [color=blue]
                  >* When a browser vendor releases a new version that fixes the bugs that
                  > allow the hack and the bugs that require the hack in the first place,
                  > the new version will automatically work like other standards compliant
                  > browsers.[/color]

                  And if the CSS parsing bug gets fixed but not the reason for the hack
                  you are screwed.
                  [color=blue]
                  >* For conditional comments that test the version number:
                  > - When a new version is released, the author needs to check whether or
                  > not the conditional comment should still apply, and update the
                  > version number as required.[/color]

                  Same applies to CSS hacks. MS CCs can be limited to current browser
                  versions with 100% accuracy, so that's another plus for CCs.
                  [color=blue]
                  >* For conditional comments that don't test the version number:[/color]

                  Which is unwise.
                  [color=blue]
                  > - When a new version is released, the author needs to check whether or
                  > not the conditional comment should still apply, and add a version
                  > number so the new version doesn't apply the hack if necessary.[/color]

                  Same check is necessary with CSS hacks.
                  [color=blue]
                  >* Conditional comments are nested within the document markup, where each
                  > and every occurance needs to be updated, whereas CSS hacks can be
                  > managed in a single external file.[/color]

                  Ever heard of S&R?

                  --
                  Spartanicus

                  Comment

                  • Lachlan Hunt

                    #10
                    Re: Conditional comments: is this new?

                    Benjamin Niemann wrote:[color=blue]
                    > <!--[if IE]><![if !IE]><![endif]-->
                    > <p>IE/Win ignores this</p>
                    > <!--[if IE]><![endif]><![endif]-->[/color]

                    This is a little less verbose than that, but I still don't approve of
                    it's usage, under any circumstances.

                    <!--[if IE 1]>-->IE/Win 5/6 ignores this<!--<![endif]-->

                    --
                    Lachlan Hunt

                    http://GetFirefox.com/ Rediscover the Web
                    http://GetThunderbird.com/ Reclaim your Inbox

                    Comment

                    • Spartanicus

                      #11
                      Re: Conditional comments: is this new?

                      Lachlan Hunt <spam.my.gspot@ gmail.com> wrote:

                      [conditional comments]
                      [color=blue]
                      >I still don't approve of
                      >it's usage, under any circumstances.[/color]

                      It's more than a little arrogant to suggest that anyone needs, or should
                      care about your "approval". Opinions are nice, but unless accompanied by
                      arguments best kept to yourself.

                      So far your arguments have been found flawed.

                      --
                      Spartanicus

                      Comment

                      • Lachlan Hunt

                        #12
                        Re: Conditional comments: is this new?

                        Spartanicus wrote:[color=blue]
                        > Lachlan Hunt <spam.my.gspot@ gmail.com> wrote:
                        >
                        > [conditional comments][color=green]
                        >>I still don't approve of
                        >>it's usage, under any circumstances.[/color]
                        >
                        > It's more than a little arrogant to suggest that anyone needs, or should
                        > care about your "approval".[/color]

                        I just didn't want it to seem as though my suggestion of a simpler
                        syntax in any way countered my earlier arguments against their use.
                        [color=blue]
                        > Opinions are nice, but unless accompanied by arguments best kept to yourself.[/color]

                        My arguments were contained in prior postings, I felt no need to repeat
                        them again.

                        --
                        Lachlan Hunt

                        http://GetFirefox.com/ Rediscover the Web
                        http://GetThunderbird.com/ Reclaim your Inbox

                        Comment

                        • Frances Del Rio

                          #13
                          Re: Conditional comments: is this new?

                          Lachlan Hunt wrote:[color=blue]
                          > Benjamin Niemann wrote:
                          >[color=green]
                          >> I've been just investigating IE conditional comments - hiding things from
                          >> non-IE/Win browsers is easy, but I wanted to know, if it's possible to
                          >> hide
                          >> code from IE/Win browsers.[/color]
                          >
                          >
                          > Conditional comments are evil for the same reasons that browser sniffing
                          > is evil. See this thread on www-style which has just been discussing
                          > this very issue.
                          > http://lists.w3.org/Archives/Public/.../thread.html#6[/color]

                          just curious Lachlan, why is browser-sniffing evil? sometimes you DO
                          have to code stuff differently for diff. browsers b/c diff. browsers
                          interpret some things differently.. here at work we do webcasts in
                          Windows Player and Real Audio and slide flips and well, a whole lot of
                          complex stuff, and we just now started supporting N/FF/M, and we've had
                          to recode a lot of stuff for these three browsers.. is it wrong in yr
                          view to do things like, for example

                          if (navigator.user Agent.indexOf(' MSIE') == -1 ) /// etc....

                          just wondering... thanks... Frances

                          Comment

                          • Henri Sivonen

                            #14
                            Re: Conditional comments: is this new?

                            In article
                            <4254e3d1$0$562 3$5a62ac22@per-qv1-newsreader-01.iinet.net.au >,
                            Lachlan Hunt <spam.my.gspot@ gmail.com> wrote:
                            [color=blue]
                            > CSS hacks are evil too, but their not as evil as conditional comments
                            > because:
                            > * They don't depend on the UA identification.[/color]

                            Isn't whole point is to work around the bugs of IE6 specifically?
                            [color=blue]
                            > * When a browser vendor releases a new version that fixes the bugs that
                            > allow the hack and the bugs that require the hack in the first place,
                            > the new version will automatically work like other standards compliant
                            > browsers.[/color]

                            What if selector bugs are fixed but other bugs not? Selectors are easier
                            to fix than profound layout issues.
                            [color=blue]
                            > * For conditional comments that test the version number:
                            > - When a new version is released, the author needs to check whether or
                            > not the conditional comment should still apply, and update the
                            > version number as required.[/color]

                            With a CSS hack, you'd have to test whether the bug the hiding is based
                            on is fixed but the bug being worked around not.
                            [color=blue]
                            > * Conditional comments are nested within the document markup, where each
                            > and every occurance needs to be updated, whereas CSS hacks can be
                            > managed in a single external file.[/color]

                            What if the conditional comment is in a single file on the server and a
                            server-side program replicates it?
                            [color=blue]
                            > So far, the *only* possibly acceptable use of a conditional comment I've
                            > seen is for Dean Edward's IE7 script, so that other browsers won't
                            > bother downloading a script they don't need.[/color]

                            Ah, so you approve of that. :-)

                            Styling fieldsets is borked in IE. What method do you suggest for
                            serving advanced styles to others and dumbed-down styles to IE?

                            I'm not a fan of conditional comments, either, but when working around
                            the bugs of IE, the risk of collateral damage with conditional comments
                            seems smaller than the risks with selector hacks or UA sniffing.

                            --
                            Henri Sivonen
                            hsivonen@iki.fi

                            Mozilla Web Author FAQ: http://mozilla.org/docs/web-developer/faq.html

                            Comment

                            • Adrienne

                              #15
                              Re: Conditional comments: is this new?

                              Gazing into my crystal ball I observed Frances Del Rio <fdr58@yahoo.co m>
                              writing in news:425533f0$0 $43986$14726298 @news.sunsite.d k:
                              [color=blue]
                              > Lachlan Hunt wrote:[color=green]
                              >> Benjamin Niemann wrote:
                              >>[color=darkred]
                              >>> I've been just investigating IE conditional comments - hiding things
                              >>> from non-IE/Win browsers is easy, but I wanted to know, if it's
                              >>> possible to hide code from IE/Win browsers.[/color]
                              >>
                              >>
                              >> Conditional comments are evil for the same reasons that browser
                              >> sniffing is evil. See this thread on www-style which has just been
                              >> discussing this very issue.
                              >> http://lists.w3.org/Archives/Public/.../thread.html#6[/color]
                              >
                              > just curious Lachlan, why is browser-sniffing evil? sometimes you DO
                              > have to code stuff differently for diff. browsers b/c diff. browsers
                              > interpret some things differently.. here at work we do webcasts in
                              > Windows Player and Real Audio and slide flips and well, a whole lot of
                              > complex stuff, and we just now started supporting N/FF/M, and we've had
                              > to recode a lot of stuff for these three browsers.. is it wrong in yr
                              > view to do things like, for example
                              >
                              > if (navigator.user Agent.indexOf(' MSIE') == -1 ) /// etc....
                              >
                              > just wondering... thanks... Frances
                              >
                              >[/color]

                              I use Opera almost exclusively, and it is really annoying and insulting so
                              see "This page requires at least IE5 or Netscape 4. Click here to upgrade
                              your browser". My bank thinks that Opera is not secure enough, so Opera
                              tricks BofA by indentifying itself as MSIE. Of course, everything works
                              just fine.

                              The real problem with browser sniffing, as I see it, is that developers get
                              lazy and don't bother to check if the page works in other browsers. A lot
                              of times, it's just bad coding on the developer's part, if the errors
                              and/or proprietary markup were fixed/removed, then the page would work just
                              fine.

                              --
                              Adrienne Boswell
                              Arbpen Consulting will help you harness valuable insights and translate them into tangible results by merging data and strategy.

                              Please respond to the group so others can share

                              Comment

                              Working...