24

I have a page that is generated which inserts an HTML comment near the top of the page. Inside the comment is a *nix-style command.

<!-- command --option value --option2 value2 --option3 -->

This comment breaks the page completely. What is wrong with the comment to cause this to happen, and why is this the case?

Community
  • 1
  • 1
Rudd Zwolinski
  • 26,712
  • 17
  • 57
  • 60

3 Answers3

27

Comments in the XML Spec from the w3.org :

For compatibility, the string "--" (double-hyphen) MUST NOT occur within comments.

mtk
  • 13,221
  • 16
  • 72
  • 112
McDowell
  • 107,573
  • 31
  • 204
  • 267
2

If you really want to keep the comment in your page you could use this instead of an HTML comment:

<div style="display:none">command --option value --option2 value2 --option3 </div>

Or even

<div class="comment">command --option value --option2 value2 --option3 </div>

and specify:

.comment {display:none;}

in your stylesheet.

Lance Fisher
  • 25,684
  • 22
  • 96
  • 122
1

Comments at the top of the page before <html> will throw IE into quirks mode, which could explain why the page breaks, if that's where your comment appears.

For more information, check out the "Triggering different rendering modes" on this wikipedia page

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Darren Kopp
  • 76,581
  • 9
  • 79
  • 93