[thelist] hiding an HTML attribute with IE-condition?

James Hardy evolt at weeb.biz
Tue Aug 24 14:05:57 CDT 2010


On 24 August 2010 18:51, Zhang Weiwu <zhangweiwu at realss.com> wrote:

> On 2010年08月23日 19:40, James Hardy wrote:
> > Well, the easy solution that springs to mind is to cheat a little, and
> write
> > the opening object tag twice using IE conditional comments, on to show
> only
> > on IE, and one to be hidden in IE 5+ (I think it is safe to ignore IE4-)
> >
> > <!--[if IE]>
> > <object>
> > <parameter src="video.wmv">
> > <![endif]-->
> >
> > <![if !IE]>
> > <object data="video.wmv">
> > <![endif]>
> >
>
> I guess this won't work. Because conditional comments are totally
> ignored by non-IEs. E.g. Firefox would read your code like this:
>
> <object>
> <parameter src="video.wmv">
>
> <object data="video.wmv">
>
> Then it is understood as two "objects".
>
> The problem is now more or less "solved" now by preparing a video in a
> second format (ogg) and use "video" tag for Firefox.
>
>
>
Actually, the conditional contents are designed to work correctly in
browsers that do not understand them, that is their power. Non IE browsers
coming across <!--[if IE]> will be see it as the start of a comment tag and
and will ignore the [if IE> and all text up to the --> after the <![endif].
IE will act in a non-standards way and render the contents

The other type of tag, <![if !IE]> and <![endif]> will be regarded as
unknown tags and ignored by browsers unfamiliar with them, which is
standard behaviour of browsers when they come across unfamiliar tags. IE
however will regard them as the start and end of a comment and will
therefore ignore the contents of the browsers

Thus IE will see:


<object>
<parameter src="video.wmv">

<!--
<object data="video.wmv">
-->

and Firefox will see

<!--
<object>
<parameter src="video.wmv">
-->

<object data="video.wmv">

For a simplif<!--[if IE]>
<div style="color:blue"> Most browsers ignore this text as it is in an HTML
comment. IE renders it however.
<![endif]-->

<![if !IE]>
<div style="color:red"> IE Ignores this text, other browsers render it.
<![endif]>

This text is common to all browsers, as is the closing tag
</div>

Here is a simplified test case which renders very differently in IE and
Firefox:

<!--[if IE]>
<div style="color:blue"> Most browsers ignore this text as it is in an HTML
comment. IE renders it however.
<![endif]-->
 <![if !IE]>
<div style="color:red"> IE Ignores this text, other browsers render it.
<![endif]>
 This text is common to all browsers, as is the closing tag of the div
element
</div>


More information about the thelist mailing list