W3C home > Mailing lists > Public > www-html@w3.org > November 2007

Re: html code in <script>

From: Mikko Rantalainen <mikko.rantalainen@peda.net>
Date: Wed, 14 Nov 2007 15:44:49 +0200
Message-ID: <473AFBD1.8010201@peda.net>
To: www-html@w3.org
David Woolley wrote:
> Paul Kieffer wrote:
>> www.ucog.org/news1.php?strArticle=NEWS/2007-10-20.htm
> The page is invalid XHTML, which means it is also invalid under Appendix 
> C rules.  If this were served as XHTML, it would need a CDATA section 
> around the script; you could also use entities to protect the "<", etc. 
>   If it were served as proper HTML, best practice would be to put an 
> HTML comment around the script content.  None of these options are 
> available under Appendix C rules (you cannot use entities to protect 
> scripts in HTML as they are implicitly CDATA sections), so you must have 
> the script out of line.

In fact, one can write something like

<script type="text/javascript">

and it will work in both HTML and XHTML mode.

Of course, if you mind about *old* browsers, you need to write something
<script type="text/javascript"><!--//--><![CDATA[//><!--

> My advise would be to revert to HTML 4.01 and use HTML comments to 
> protect the scripts against earlier browsers.  Many people think that 
> Appendix C (serving XHTML as text/html) was a bad idea; it relies on 
> certain non-compliances that are common in text/html browsers.

I agree. If you want to use XHTML, the best way is to check the
Accept-header and if it doesn't contain "application/xhtml+xml" then the
server must encode the content as a real HTML document. Sending an XHTML
file with "text/html" content type will not win anything over real HTML
and can cause problems in the worst case.


Received on Wednesday, 14 November 2007 13:45:07 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:06:17 UTC