W3C home > Mailing lists > Public > www-validator@w3.org > June 2005

Re: SCRIPT and embedded markup

From: Lachlan Hunt <lachlan.hunt@lachy.id.au>
Date: Wed, 01 Jun 2005 23:37:49 +1000
Message-ID: <429DBA2D.8040001@lachy.id.au>
To: Undeference@netscape.net
CC: www-validator@w3.org

Undeference@netscape.net wrote:
> Obviously code like below is a nesting problem:
> <script type="text/javascript">
> // This should go between <head> and </head>
> </script>
> But the reason for there being even a mention to the invalidity of the
> following is astounding (from
> <http://www.htmlhelp.com/tools/validator/problems.html#script>:
> <script type="text/javascript">
> <!--
>   // This is an error!
>   document.write("</P>");
> // -->
> </script>
> The purpose of commenting out the script content is to hide it from
> old (really old) browsers so that only newer browsers handle it.

Yes, but the only reason it works is because no browser reads the DTD; 
and such browsers are, therefore, unawre that the script element is 
defined with a content model of CDATA (character data) and continue to 
process it as PCDATA (parsed character data).

> However, just because UAs stoop to the level of snooping out comments
> to support an outdated and improper hack does not mean a validator
> should.

The reason browsers read the content of the script, despite it appearing 
to be within an HTML comment <!-- ... --> is because it's not really a 
comment.  Please see HTML Comments in Scripts for a thourough explanation.


> As far as a validator that *properly* parses HTML or XML documents,
> the above code should be exactly identical to the following:
> <script type="text/javascript">
> </script>

That's correct for XHTML, but wrong for HTML.

Lachlan Hunt
Received on Wednesday, 1 June 2005 13:38:04 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:58:51 UTC