Conditional Comments on Mozilla?




HTML: Parser
16 years ago
10 years ago


(Reporter: maks, Assigned: harishd)



Firefox Tracking Flags

(Not tracked)


(Whiteboard: WONTFIX?)



16 years ago
ie has some usefull toll, which works with their broser upward to 5.0
they called this "Conditional Comments":

how could i have a workaround that only shows a portion of code in the newer
mozilla / netscape browser and not in ie
(this would be usefull for only showing to mozilla/netscape the sidebar feature)

a little bit like this one but not shown in netscape 4.x
You are using NS 4 or above!

thanks for your help, i found the ie conditional comments usefull perhaps you
could add their syntax to mozilla. what do you think?
with best regards

Comment 1

16 years ago
there are no conditional comments, but there is a workaround
navigator.userAgent can be used to check the browser and depending on the return 
value you can write the code which applies to particular browser.
Severity: normal → enhancement
Ever confirmed: true
Priority: -- → P5
You are using NS 4 or above!

That's incorrect.  Neither NS 6.x nor Mozilla support that document.layers.

In any case, how is that better than writing:

<script language="JavaScript">
if (document.layers != null)
  document.write("You are using NS 4!")

The second way it is clear you are writing JavaScript code.  Your proposed way
could be using VBScript, Tcl, who knows?

More importantly, the standard <script> works in ALL browsers which support
scripts.  What you proposed only currently works in MSIE.  Even if Mozilla does
support it, it is non-standard and there will be countless other browsers which
do not support it.  Our support of this non-standard feature will encourage it's
use which will be bad for the web.

Comments are meant to be comments, not scripts.  If you want to use a script,
then enclose it in script tags.
Severity: enhancement → normal
Priority: P5 → --

Comment 3

16 years ago
we are using the priority field for setting the importance of the bug. Please do 
not change the priority field to null. If you disagree with the priority set by 
anyone, feel free to change it :) 
Severity: normal → enhancement
Priority: -- → P5

Comment 4

16 years ago
thanks for your usefull posts and comments.
i can understand your point of view focussing on standards,
but the force of the related function in the ie is that it works only on that
browser even without javascript!
so the argument that it would not work on all browsers turns out to be an
argument in favour of this conditional comments.
Stummalla, that is because of a midair collision gone bad.  I didn't touch those
fields but they got changed anyway.  Sorry.
Maks, on the contrary.  If that works in IE _without_ JavaScript then I would
consider that a privacy invasion.  If I turn off JavaScript, I do not want any
pages to be able to access anything about my scripting environment.  I said no
JavaScript, and I don't want pages to be able to learn my navigator.appName or
document.layers or anything about my browser.

That "feature" defeats the whole purpose of being able to turn JS off.  If you
want to access a JS property, you should be forced to use conventional <script>
methods and it's access restrictions, if any.

Comment 7

16 years ago
Christopher, I didn't try it on IE without JavaScript, but the official
Microsoft tells us that you do not need any scripting. So "Conditional Comments"
should work even with deactived JS!
"It is not always necessary to use scripting and DHTML when working with
conditional comments, and when no scripting is used in a Web page, no scripting
engine needs to be loaded."

Comment 8

16 years ago
maks, (document.layers!=null) is a javascript statement. if such a conditional
comment doesn't require javascript to be enabled to be evaluated, then it's a
serious privacy issue, because you're effectively running potentially dangerous
javascript even when it is disabled.

Comment 9

16 years ago
Fabian, the following downlevel-hidden conditional comment shown on the
microsoft page (link above) checks for you ie browser version:
<!--[if IE 5]>
<p>Welcome to Internet Explorer 5.</p>
I don't know much about JS so I don't know if you meant that the statement above
(working with deactived JS) is equivalent to (document.layers!=null) with
actived JS.
If I might interrupt...

The HTML comment syntax is very well defined.  The sequence of characters "<!"
does not mean "I get to make up what I do with it" but rather has a very
particular meaning in SGML and XML applications.

Looking at the examples listed on the page you reference:

<!--[if expression]> HTML <![endif]-->

Any browser that's claiming to be HTML-compliant should hide the content, unless
"HTML" contains the characters "--"

<![if expression]> HTML <![endif]>

In this case the [if expression] and [endif] should be interpreted as SGML
markup (possibly being ignored if they make no sense).

I fail how we can implement this feature (especially the "downlevel-hidden"
part) without completely breaking standards-compliant comment parsing.  For
example, what does IE do with the following?

<!--[if IE 6]>
This is a test -- a test.
<![endif]--> Red ball.

If the words "Red ball" are visible in IE6 in CSS1Compat mode that's bad.

In the words of Arjun Ray when this came up on the W3C lists (February 2000), "Phony Baloney".  The right way to do this sort of thing is a PI or markedsection, certainly not a comment.  Given that this doesn't work in Opera, Lynx,&etc., will probably generate Issues with quirks comment parsing (as bz pointsout), and is generally a stupid abuse of markup, I suggest WONTFIX.The idea of delivering different parts of a single document to differentbrowsers/platforms using only markup is not entirely uninteresting, but as usual,MS failed to RTFM; I can't see that the mixed blessings of easier (but possiblymore wrong) browser-sniffing are worth the effort of implementing this kludge.Over to Parser, which is somewhat more apt as a component.
Assignee: jst → harishd
Component: DOM HTML → Parser
QA Contact: stummala → moied
Whiteboard: WONTFIX?
Um, I'm far from convinced that the world would be a better place if Mozilla
chose to support a syntax this messed up. I vote for WONTFIX.

Comment 13

16 years ago
I don't think it's worth the effort to fix this. WONTFIX.
Last Resolved: 16 years ago
Resolution: --- → WONTFIX

Comment 14

16 years ago
verified WONTFIX

Comment 15

14 years ago
One way to attack IE conditional comments without polluting the comment parsing
logic might be through feature request:

Bug 86504 (HTML Filter with Regular Expressions)

I also see some parser filtering stuff in htmlparser/public/nsIParserFilter.h --
is this being used by anything?

Comment 16

14 years ago
I have a project at that filters out ie-style
conditional comments before they hit the parser.

Comment 17

14 years ago
*** Bug 217581 has been marked as a duplicate of this bug. ***
Duplicate of this bug: 380198
Duplicate of this bug: 398016
You need to log in before you can comment on or make changes to this bug.