JavaScript Editor Free JavaScript Editor     JavaScript Debugger 




Main Page

Previous Page
Next Page

6.4. Comments

From an XML point of view, Listing 6-7 is well formed; unfortunately, some web browsers would have an issue with it as part of a web page. A method is needed to hide the JavaScript from XML, and the CDATA section tags from both the browser and the browser's JavaScript interpreter. This can be accomplished with XML comment tags, which, by the way, are identical to the comment tags from HTML. Because the JavaScript interpreter has problems only with the CDATA section's closing tag, a // is enough to make the browser look the other way. The end result is the node shown in Listing 6-8.

Listing 6-8. A Well-Formed Cross-Browser Script Element

            <script language="JavaScript">
<!-- <![CDATA[
function hello(intTimes) {
      for(var i=0;i < intTimes;i++)
            alert('Hello, World!');
}
// ]]> -->
             </script>


Previous Page
Next Page

R7


JavaScript Editor Free JavaScript Editor     JavaScript Debugger


©