Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: encoding of script tags in html

From: "Andy Fish" <ajfish@----------.--.-->
To: NULL
Date: 6/2/2008 3:09:00 PM

thanks to both for the quick replies

wow - what a minefield this has turned out to be !!

i previously had just one server-side utility function to escape a string as 
a literal javascript string. now i realise i need to have 2 separate 
functions, one for when the javascript literal is to be placed inside an 
HTML attribute value (e.g. onclick="...") and a different one for when it is 
inside a script block, because one is CDATA and one is PCDATA

Andy


"Martin Honnen" <mahotrash@y...> wrote in message 
news:4843e357$0$27438$9b4e6d93@n......
> Andy Fish wrote:
>
>> can someone point me at part of the w3c specification that states how 
>> script tags are parsed differently to other tags in HTML.
>
> See http://www.w3.org/TR/html4/types.html#type-script:
>   "Please note that script data that is element content may not contain 
> character references, but script data that is the value of an attribute 
> may contain them."
> and http://www.w3.org/TR/html4/appendix/notes.html#notes-specifying-data:
>   "The DTD defines script and style data to be CDATA for both element 
> content and attribute values. SGML rules do not allow character references 
> in CDATA element content but do allow them in CDATA attribute values."
>
>> interestingly i have also discovered that this:
>>
>> <script>if (3<5);</script>
>>
>> IS valid html and seems even to be valid XHTML even though it is not 
>> valid XML
>
> That snippet is not well-formed so it can't be valid XML or XHTML as it is 
> not even XML.
>
>
> -- 
>
> Martin Honnen
> http://JavaScript.FAQTs.com/ 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent