Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comments affect Page display in Netscape 7.0 1

Status
Not open for further replies.

TonyJollans

Programmer
Dec 18, 2002
7,186
GB
Hi All,

Not my normal forum so I hope I've chosen the right one. I'm not quite a newbie but I'm not very experienced in this and am stumped. Any explanations would be gratefully received.

I've been trying to be a good little boy and, apart from what I'm told is my own inimitable style, trying to code up web pages 'properly'. All appears to work well in IE but in Netscape 7.0 I have been getting odd results which I have managed to pin down to be because of my comments.

Firstly, my page looks like this - the doctype and the start of the body section and the comment is reproduced EXACTLY, the rest just shows the general structure:

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
                      &quot;[URL unfurl="true"]http://www.w3.org/TR/html401/loose.dtd&quot;>[/URL]

<HTML>
  <HEAD>
    <TITLE> ... </TITLE>
    <META ...>
    <SCRIPT Language = &quot;JavaScript&quot; Type = &quot;Text/JavaScript&quot;>
      <!--
Code:
(some javascript routines)
Code:
      // -->
    </SCRIPT>
    <STYLE Type = &quot;Text/CSS&quot;>
      <!--
Code:
(some style definitions)
Code:
      -->
    </STYLE>
  </HEAD>
  <BODY BgColor=&quot;#000000&quot;>

<!---------------------------    Page content starts here    ---------------------------->

    <center>
      <img ....>
Code:
(rest of page content including some more comments like the one above)
Code:
  </Body>
</HTML>

Now, when I display this in Netscape (7.0) I see nothing. The fact that it is nothing rather than a partial something does not appear to be significant, merely a consequence of the placement of comments. When I remove the URL from the DOCTYPE, my page displays as I intended, so I have a fix (of sorts) but I want to be able to avoid hitting the same problem over and over again.

I have tried to pin down the problem and found the following:

This works:

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
                      &quot;[URL unfurl="true"]http://www.w3.org/TR/html401/loose.dtd&quot;>[/URL]

<HTML>
  <BODY>
<!-- -->
Test
  </BODY>
</HTML>

The page displays Test

------------------------------------------------------------------------------------------------------------

This (with extra minus signs) doesn't:

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
                      &quot;[URL unfurl="true"]http://www.w3.org/TR/html401/loose.dtd&quot;>[/URL]

<HTML>
  <BODY>
<!---- -->
Test
  </BODY>
</HTML>

The page displays ---- --> Test

------------------------------------------------------------------------------------------------------------

But this (without the URL) does:

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>

<HTML>
  <BODY>
<!---- -->
Test
  </BODY>
</HTML>

The page displays Test

------------------------------------------------------------------------------------------------------------

Much the same happens with the comment after the text, so this fails:

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
                      &quot;[URL unfurl="true"]http://www.w3.org/TR/html401/loose.dtd&quot;>[/URL]

<HTML>
  <BODY>
Test
<!---- -->
  </BODY>
</HTML>

.. displaying Test ---- -->

-----------------------------------------------------------------------------------------------------------

Comments before and after the text seem to produce even more dramatic results (such as I originally had):

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
                      &quot;[URL unfurl="true"]http://www.w3.org/TR/html401/loose.dtd&quot;>[/URL]

<HTML>
  <BODY>
<!--- ----->
Test
<!-- ---->
  </BODY>
</HTML>

.. displays nothing


Finally, my understanding of comments is as follows:

The DOCTYPE statement at the start of the page is actually SGML.
The URI points to a formal declaration of the version of the HTML standard to which the document is written.
HTML does not have a comment construct of its own and (in theory) borrows the SGML one.
SGML statements begin with <! and end with >.
SGML comments within an SGML statement are delimited by -- before and after.
The HTML interpretation of this SGML construct is for comments to be delimited by <!-- and -->.
Comments in HTML cannot be nested.

What have I misunderstood?

Thanks In Advance,
Tony
 
Using the full DOCTYPE, including the URL, will get the browser to interpret the page in strict accordance with the specified standard. Missing out (part of) the DOCTYPE declaration will cause the browser to operate in &quot;quirks&quot; mode - where different browsers behave in different ways just like the bad old version 4 days.

Netscape is generally a good deal more fussy about standards compliance than IE, and apparently it's objecting to you not having a space after the begin comment delimiter. A quote from the HTML4.01 standards (my italics):

&quot;White space is not permitted between the markup declaration open delimiter(&quot;<!&quot;) and the comment open delimiter (&quot;--&quot;), but is permitted between the comment close delimiter (&quot;--&quot;) and the markup declaration close delimiter (&quot;>&quot;). A common error is to include a string of hyphens (&quot;---&quot;) within a comment. Authors should avoid putting two or more adjacent hyphens inside comments.&quot;

Try running your pages through the validator at to pick up errors like this.

-- Chris Hunt
 
Thanks Chris,

I have read the standard before but it obviously didn't sink in; I guess I thought I knew what it said and didn't actually read it properly. That said, it is a pretty loose definition to be in a standard.

It says (my italics this time) Information that appears between comments has no special meaning; yet multiple hyphens obviously do have special meaning. It notes a common error which does not break any stated rule and goes on to say that authors should avoid putting two or more adjacent hyphens inside comments. I guess we must interpret that as meaning it is not actually allowed.

Anyway, thanks for the help; I am all sorted now. Have a purple thingy.

Thanks,
Tony
 
Hi Chris,

Thought about this overnight - I know, it's sad - and I was probably (again) a bit presumptive in my reading of the standard. I still think it's a bit odd, and poorly presented in the standard, but I do now think I understand. Please correct me if I'm wrong.

HTML does not have a comment construct of its own, but browsers will recognise SGML statements which do include a comment construct and that is deemed to provide sufficient capacity.

Although nested comments aren't allowed (and can't work when the start and end delimiters are the same), multiple consecutive comments within an SGML statement seem to be allowed (comments being white space which is allowed between the comment end delimiter and the markup end delimiter).

This being so ..

<!-- first comment -- -- second comment -->

.. and similar constructs, should be valid SGML comments and treated as such by all browsers (which they quite probably are), but behaviour is undetermined when code is invalid so ..

<!-- comment -- non-whitespace and so illegal after comment end delimiter -->

.. could (and does) produce variable results.

I think this explains all my results, but if I spend this long trying to understand comments I'll never be a webmaster [smile]

Do you know where I can find the SGML standard? Or do I have to buy it?

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top