Does anyone know the do's and don't of commenting in FireFox 3.x?
I decided to show a breaking version of what I am talking about. It is not important how it messes up the layout, only that it causes the DIV element to be null....
<!-- [ top panel ] --><div id="top_panel">
<!-- -------------------------------------- -->
<script type="text/javascript">
alert(document.getElementById('top_panel'));
</script>
</div>
The above code will return the element as null, every time.... if I increase or decrease the number of dashes it still fails as long as the interior dashes end with a closing pair of dashes. For the sake of example, I will use [open] and [close] to represent pairs of "--" dashes...
So, the code ends up being interpreted this way to break:
<!-- [close]开发者_如何学编程[open][close][open][close][open][close][open][close] -->
In this example, it is the last [close] and the "-->" which now cause an open, hanging comment.
I only seem to run into comment-based issues in FF these days. All other browsers seem okay with anything I have thrown at them...
I KNOW that this is not considered legal commenting, but it still does not change the fact that I had to trip over this situation to become aware of the issue... I am hoping others can avoid the same simple problem and share their own twists on weird, comment-based issues in any browser... I am sure this is not the only instance of good commenting gone bad.
I also understand that leaving a space after the "<" is a no-no as well: "<" + " " + "!" + "--" = Nooooo!
Thanks for all your help, all!
You can't use --
inside comments because it ends the comment. This isn't a Firefox thing - it's defined by the standards. Any browser that doesn't treat --
as start/end of comment is doing it wrong and most likely will be bug-fixed eventually.
White space is not permitted between the markup declaration open delimiter("<!") and the comment open delimiter ("--"), but is permitted between the comment close delimiter ("--") and the markup declaration close delimiter (">"). A common error is to include a string of hyphens ("---") within a comment. Authors should avoid putting two or more adjacent hyphens inside comments.
Are you serving XHTML? According to the XML standard,
For compatibility, the string " -- " (double-hyphen) MUST NOT occur within comments.
Edit: the same restriction exists in regular HTML, too.
精彩评论