? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes

Discussion in 'HTML' started by Alec S., Apr 15, 2005.

  1. Alec S.

    Alec S. Guest

    Hi,

    Whenever I see conditional comments used, they are used for CSS-to include a
    CSS file for IE.

    I am trying to use them for something else. I have a page that has a DIV
    which when viewed in IE should support dragging and right-clicks but I also
    want it to validate. Is there an ELSE/ELSEIF tag I can use like this:

    <!--[if IE]>
    <div onclick="func1();" ondrag="func2();" oncontextmenu="func3();">
    <![elseif]> (or <![else]>)
    <div onclick="func1();">
    <![endif]-->


    I also tried:
    <div onclick="func1();" <!--[if IE]> ondrag="func2();"
    oncontextmenu="func3();" <![endif]--> >

    Speaking of which can you use them inside tags to comment out attributes
    like:
    <img src="blah" <!--[if IE]> src="blah2" <![endif]--> />
    or use different ones like:
    <img src="blah" <!--[if IE]> height="10" <![endif]--> />


    Neither one works properly. Is there a way to fix it or another way I can
    do this?


    thanks.

    --
    news <.> alec <@> synetech <.> cjb <.> net
    Alec S., Apr 15, 2005
    #1
    1. Advertising

  2. Alec S.

    Spartanicus Guest

    "Alec S." <> wrote:

    >Whenever I see conditional comments used, they are used for CSS-to include a
    >CSS file for IE.
    >
    >I am trying to use them for something else. I have a page that has a DIV
    >which when viewed in IE should support dragging and right-clicks but I also
    >want it to validate. Is there an ELSE/ELSEIF tag I can use like this:
    >
    ><!--[if IE]>
    ><div onclick="func1();" ondrag="func2();" oncontextmenu="func3();">
    ><![elseif]> (or <![else]>)
    ><div onclick="func1();">
    ><![endif]-->


    There are MS "downlevel revealed" conditional comments, but they don't
    validate.

    >I also tried:
    > <div onclick="func1();" <!--[if IE]> ondrag="func2();"
    >oncontextmenu="func3();" <![endif]--> >
    >
    >Speaking of which can you use them inside tags to comment out attributes
    >like:
    > <img src="blah" <!--[if IE]> src="blah2" <![endif]--> />
    >or use different ones like:
    > <img src="blah" <!--[if IE]> height="10" <![endif]--> />


    No, you cannot nest tags.

    --
    Spartanicus
    Spartanicus, Apr 15, 2005
    #2
    1. Advertising

  3. Alec S.

    mbstevens Guest

    Alec S. wrote:

    > Hi,
    >
    > Whenever I see conditional comments used, they are used
    > for CSS-to include a CSS file for IE.
    >
    > I am trying to use them for something else. I have a
    > page that has a DIV which when viewed in IE should
    > support dragging and right-clicks but I also
    > want it to validate. Is there an ELSE/ELSEIF tag I can
    > use like this:
    >
    > <!--[if IE]>


    No, there are no such tags.
    Such fishing can be done (imperfectly) in javascript, or
    with server side tests. It's not a good idea; but if you
    feel you absolutely must -- you could combine such
    testing with information from the several articles about
    style-switching found at alistapart.com.
    --
    mbstevens http://www.mbstevens.com
    mbstevens, Apr 15, 2005
    #3
  4. Alec S.

    Alec S. Guest

    So how can I support/use a proprietary tag/attribute and still validate the
    basics stuff? Using [if IE] for style validates.

    --
    news <.> alec <@> synetech <.> cjb <.> net
    Alec S., Apr 15, 2005
    #4
  5. Alec S.

    Steve Pugh Guest

    "Alec S." <> wrote:

    >So how can I support/use a proprietary tag/attribute and still validate the
    >basics stuff?


    Well that's the question. If you are using non-standard attributes why
    are you trying to fool the validator into passing your page as valid
    HTML?

    If you want the benefits of validation AND the use of non-standard
    code (presumably for an intranet or other controlled usage) then you
    can write your own DTD and validate against that.

    Steve

    --
    "My theories appal you, my heresies outrage you,
    I never answer letters and you don't like my tie." - The Doctor

    Steve Pugh <> <http://steve.pugh.net/>
    Steve Pugh, Apr 15, 2005
    #5
  6. Re: ? ELSE Conditional Comment / Using Conditional Comments InsideOther Tags To Comment Out Attributes

    Alec S. wrote:
    > Whenever I see conditional comments used, they are used for CSS-to include a
    > CSS file for IE.
    >
    > I am trying to use them for something else. I have a page that has a DIV
    > which when viewed in IE should support dragging and right-clicks but I also
    > want it to validate.


    Validation is a means to an end, not an end in itself. Tricking the
    validator won't magically make your page work any better. What's the point?
    Leif K-Brooks, Apr 16, 2005
    #6
  7. Alec S.

    Alec S. Guest

    "Steve Pugh" <> wrote in message
    news:...
    > Well that's the question. If you are using non-standard attributes why
    > are you trying to fool the validator into passing your page as valid
    > HTML?



    What I want to do is to make a page that works in all browsers and thus
    validates but also has extra features depending on the browser used. If it
    has the same basic functionality it should be "valid". Extra functions are
    just that, extra, or bonus.

    I understand the whole standards thing, I'm all for accessibility, but
    pandering to the lowest common denominator (text browsers, browsers that
    don't support tables, etc.) is a hindrance to progress. It's not
    Microsoft's fault that the standards committees have not yet added support
    for things like dragging events and I find it frustrating that I have to
    limit the functionality of my site to validate. Web pages are no longer
    static pages with text that you read and move on, people now expect
    interactivity, customization, and dynamic content. I suppose I could ignore
    the 1 warning since browsers that don't support ondrag/oncontextmenu ignore
    it.


    --
    news <.> alec <@> synetech <.> cjb <.> net
    Alec S., Apr 16, 2005
    #7
  8. Alec S.

    Andy Dingley Guest

    On Fri, 15 Apr 2005 19:28:57 -0400, "Alec S." <> wrote:

    >What I want to do is to make a page that works in all browsers and thus
    >validates


    >I understand the whole standards thing,


    From the first statement, you don't.

    > but also has extra features depending on the browser used.


    Wrong approach. Put the features on anyway, and serve the same content
    to all browsers.

    But just check that adding these extra features doesn't break anything
    for the non-supporting browsers. You don't need to "switch them off"
    or hide them if they won't work, you can just let the browser deal
    with this in most cases. In some cases you deliver a page where
    they're not "live" and you turn them on locally, by a bit of
    client-side JavaScript that can test for them.

    It's all about degradation. Don't ask "How do I avoid this
    happening?", ask instead "What is the result if this does happen?"
    You _can't_ control stuff, you _can't_ detect what the far end is up
    to and you _certainly_ can't predict what devices will be around in 5
    years time. CSS is well-designed for this - design your site
    correctly and the text-only browser can make good sense of what you
    gave it, even without intervention.

    In a _few_ cases, you need to serve a completely different page. The
    only one that comes is mind offhand is for client-side XSLT and XML
    data islands. This requires such a radical re-design that there's no
    real option (for maintainable code)

    If you're interested in the near-edge of browser sniffing technology,
    then take a look as CC/PP. It's interesting, but it's still no bloody
    use for anything practical.

    _Nowhere_ do you need the blecherous abomination that is the M$oft
    "conditional comment". This is a feature invented by teenagers not
    software engineers. No-one who has spent years beating old assembler
    code with a stick, or maintained old c code that was rotten with
    pre-processor directives, could possibly see this as a good thing.


    >pandering to the lowest common denominator (text browsers, browsers that
    >don't support tables, etc.) is a hindrance to progress.


    It would be, except that you don't need to pander to them. Not even a
    slightly-threatened ocelot.


    Validation is over-hyped (especially here). It's a _convenient_ test
    for whether a page has some obvious problems in it. However the
    design of the web architecture is such that some bits of validation
    can be trashed quite heavily without damage, _if_ you know what you're
    doing and you know that that particular invalidity is non-harmful
    within context.

    As a general rule, enjoy yourself with attributes. I stick XML
    namespaced attributes all over the place for some metadata purposes
    and I can _know_ that they're non-damaging because they're hidden
    behind the namespacing and the strong HTML rules on ignoring unknown
    attributes.

    So you want some extra attributes for event handlers - go to it. As
    a comment on the standards path, then I don't regard their absence as
    any more than trivial. Tthere are more important things, like the
    bogosity of DocBook, or the unwarranted deprecation of <menu> to worry
    about.

    In a real standards-driven environment for useful event trapping, then
    it needs to be a substantially more sophisticated and dynamic
    mechanism than just taking M$oft marketing's favourite names for the
    next year's new event features and sticking them into the spec at the
    last minute. If you care, go read up on XForm.

    --
    Cats have nine lives, which is why they rarely post to Usenet.
    Andy Dingley, Apr 16, 2005
    #8
  9. Re: ? ELSE Conditional Comment / Using Conditional Comments InsideOther Tags To Comment Out Attributes

    Andy Dingley wrote:
    > _Nowhere_ do you need the blecherous abomination that is the M$oft
    > "conditional comment". This is a feature invented by teenagers not
    > software engineers.


    Please don't insult us teenagers!
    Leif K-Brooks, Apr 16, 2005
    #9
  10. Alec S.

    Alec S. Guest

    "Leif K-Brooks" <> wrote in message
    news:J5Y7e.1857$...
    > Validation is a means to an end, not an end in itself. Tricking the
    > validator won't magically make your page work any better. What's the

    point?


    I didn't want to trick it, I wanted to find a "valid" way to handle dragging
    and right-clicking.


    --
    news <.> alec <@> synetech <.> cjb <.> net
    Alec S., Apr 16, 2005
    #10
  11. Alec S.

    Alec S. Guest

    Well it is just the one page that has the extra stuff (it's a
    user-preference setting page). So I can live with one warning on it. The
    rest of the pages are fine. Wanting to validate-besides making sure the
    page is properly formatted-is because "Valid XXX" is a status thing that
    gives users comfort. Of course being educated about the proper use of the
    Internet and all it's dangers would comfort them more.

    As for not needing conditional comments, like I said they are usually used
    to compensate for IE's CSS implementation bugs, so I would think they are
    required.

    --
    news <.> alec <@> synetech <.> cjb <.> net
    Alec S., Apr 16, 2005
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. A. Brinkmann
    Replies:
    2
    Views:
    1,072
    A. Brinkmann
    Apr 16, 2004
  2. Replies:
    3
    Views:
    628
  3. Replies:
    0
    Views:
    505
  4. adeger
    Replies:
    2
    Views:
    304
    Duncan Booth
    Sep 22, 2004
  5. Dave
    Replies:
    0
    Views:
    448
Loading...

Share This Page