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

A

Alec S.

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.
 
S

Spartanicus

Alec S. said:
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.
 
M

mbstevens

Alec said:
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.
 
A

Alec S.

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

Steve Pugh

Alec S. said:
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
 
L

Leif K-Brooks

Alec said:
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?
 
A

Alec S.

Steve Pugh said:
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.
 
A

Andy Dingley

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.
 
L

Leif K-Brooks

Andy said:
_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!
 
A

Alec S.

Leif K-Brooks said:
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.
 
A

Alec S.

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top