If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

HTML Comment Tags make Javascript no work

RESOLVED WORKSFORME

Status

()

Core
HTML: Parser
RESOLVED WORKSFORME
14 years ago
14 years ago

People

(Reporter: Juan Manuel González, Unassigned)

Tracking

Trunk
x86
Windows 2000
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

(Reporter)

Description

14 years ago
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

14 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

14 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
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

14 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.
Juan Manuel González, any chance of a response to the questions in comment 1 and
comment 2?  As things stand, there is nothing that can be done to fix this bug;
if there is no response within another month or so, we'll have to just mark it
invalid...

Comment 6

14 years ago
Created attachment 147690 [details]
JavaScript recognized in comments

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.
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
Last Resolved: 14 years ago
Resolution: --- → WORKSFORME

Comment 8

14 years ago
Created attachment 147692 [details]
Invalid commenting breaks JavaScript

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.