Return to Snippet

Revision: 26594
at May 3, 2010 12:39 by PapillonUK


Updated Code
<!-- XHTML -->
<script type="text/javascript">
//<![CDATA[
   // Your unescaped Javascript here...
//]]> 
</script>


<!-- HTML 4.01 -->
<script type="text/javascript">
   // Your unescaped Javascript here...
</script>

Revision: 26593
at May 3, 2010 12:19 by PapillonUK


Updated Code
<!-- XHTML -->
<script type="text/javascript">
<![CDATA[
 ... unescaped script content ... 
]]> 
</script>


<!-- HTML 4.01 -->
<script type="text/javascript">
 ... script content ... 
</script>

Revision: 26592
at May 3, 2010 12:07 by PapillonUK


Initial Code
<script type="text/javascript">
<![CDATA[
 ... unescaped script content ... 
]]> 
</script>

Initial URL

                                

Initial Description
This is the correct markup for an inline script tag for HTML 4.01 and XHTML 1.0
Note the lack of any "language" attribute since this is deprecated.

In HTML 4, the content type is declared as CDATA, which means that entities will not be parsed. 

In XHTML, the content type is declared as (#PCDATA), which means that entities will be parsed. So to avoid having to encode the data between the <script> tag with enclose it in a CDATA section.
Some older browsers don't recgnise the CDATA tag so we "hide" them in Javascript comments "//"
This allows the page to be validated and also still work in older browsers.

Initial Title
Correct sytax for the XHTML & HTML 4  tag

Initial Tags
javascript, script

Initial Language
JavaScript