Closed
Bug 234156
Opened 21 years ago
Closed 21 years ago
HTML Comment Tags make Javascript no work
Categories
(Core :: DOM: HTML Parser, defect)
Tracking
()
RESOLVED
WORKSFORME
People
(Reporter: jmg_al, Unassigned)
Details
Attachments
(2 files)
User-Agent:
Build Identifier: Mozilla 1.6
Some programers use to put the html comment tags between the <script> tags. i.e:
<script><!-- --> </script>. If I do this in Mozilla, the script code isnt
recognized by the navigator, and this work in IE and Netscape. Another similar
bug is when you write <!----> . THe navigator only reads "<!--", but no "-->"
Reproducible: Always
Steps to Reproduce:
1.write <script><!--
2.then, for example, function problem() {alert("NO PROBLEM!!");}
3.-->
4.- in the HTML Page, call the function problem, and it won't work
Actual Results:
The function problem isnt invoked
Expected Results:
the function should be invoked
Comment 1•21 years ago
|
||
How about pasting in an exact code snippet, rather than a prose description of it?
In particular:
- Do you have a newline between the <!-- and the first line of actual JS code?
This is essential, because <!-- is a notation for a single-line comment in JS.
- You also need a // on the same line before the closing -->. At least
according to the spec if I'm not mistaken.
Comment 2•21 years ago
|
||
Possibly relevant: if you're using XHTML, <!-- will actually comment out the
text completely.
“[In] XHTML, <script> and <style> elements are #PCDATA blocks, not #CDATA
blocks, and therefore <!-- and --> really _are_ comments tags, and are not
ignored by the XHTML parser. To escape script in an XHTML document which may be
handled as either HTML4 or XHTML, you have to use:
<script type="text/javascript"><!--/*--><![CDATA[//><!--
...
//--><!]]></script>”
--- http://www.hixie.ch/advocacy/xhtml
Comment 3•21 years ago
|
||
Why bother? Any browser that doesn't recognize <script> has to be from around
the Netscape 2 era, and >99.9% of pages with comments in <script> wouldn't work
on such browsers anyway. It's just a cargo-cult artifact, and there's no need
to bother with these elaborate hacks.
Anyway, attach a testcase to the bug and we'll see.
Assignee: general → parser
Component: JavaScript Engine → HTML: Parser
Comment 4•21 years ago
|
||
(In reply to comment #3)
> and >99.9% of pages with comments in <script> wouldn't work
> on such browsers anyway.
I never knew that graceful degradation was that unheard-of.
Comment 5•21 years ago
|
||
Comment 6•21 years ago
|
||
An alert window is opened when the attached Web page is viewed. Because of the
DocType and encoding, page is rendered in Standards compliance mode.
Comment 7•21 years ago
|
||
Right. So the bug doesn't exist in that testcase...
I'm marking this bug worksforme, per lack of response from reporter.
Status: UNCONFIRMED → RESOLVED
Closed: 21 years ago
Resolution: --- → WORKSFORME
Comment 8•21 years ago
|
||
There is no newline before the JavaScript alert(). The alert will not pop up a
window. Because of the DocType and encoding, page is rendered in Standards
compliance mode.
Internet Explorer (IE 6, SP1, WinXP) renders this Web page the same way that
Mozilla does: the alert box is not displayed.
This appears to be correct behavior when information is included on the same
line as the comment (within the comment, basically). When the alert is on a
new line, it is parsed and executed. The closing comment must not be on the
same line as the JavaScript to be executed either -- otherwise the JavaScript
will be ignored.
You need to log in
before you can comment on or make changes to this bug.
Description
•