I put a block of code in script tags in the header of my webpage with <![CDATA[ ]]> instead of <!– –> and not it no longer works. However, I thought CDATA was the more correct way to include the code.
@scragarJan 22.2008 — #[code=html]<script type='text/javascript'> /* <![CDATA[ */ // code /* ]]> */ </script>[/code]only a few browsers automaticly escape the cdata tags, for the rest you want to use javascript comments on/around the tags opening and closing.
@felgallJan 23.2008 — #Inline JavaScript in HTML is CDATA by default and hence doesn't need the CDATA tag.
Inline JavaScript in XHTML is PCDATA by default and so needs the tag which will then be correctly interpreted without the surrounding comments.
If you are using XHTML 1.0 and are serving it as HTML for Internet explorer then you need both the CDATA tag (for validation and browesers that understand XHTML) and need the comments around it so that IE can handle it as HTML.
The <!-- --> comments are only needed for visitors using IE2 or Netscape 1 and are not needed if all your visitors are using more recent browsers than that.
I would like to have everything in an external js file. However, I need to pass a php variable to the javascript I am using (I am working on implementing someone else's slideshow here; I am passing the "count" variable), so I have resorted to putting a small block of script in the actual webpage header, and then calling the object functions later in the body of the page.
So my follow-up question is, after looking at my implementation of the javascript of that example I gave above, is there anyway to get it all in an external js file? Or do you have any other feedback on how my javascript code looks on that page?