• home
  • forum
  • my
  • kt
  • download
  • Making JavaScript to be XHTML compliant

    Author: 2007-07-19 11:22:00 From:

    Every webmaster has experienced the need to create XHTML compliant web pages. If you are a web designer with clients I'm sure you've heard it many times from your clients who demand to have their web pages built this way. How do we make a page that contains DHTML scripts to be XHTML compliant? This is not a dificult process as you will see if you're reading this till the end.

    There are two easy and short ways of doing this possible.

    1: If we use inline Javascript, we can wrap the code inside the CDATA tag in, conjunction with some Javascript comments to show to the validator that our content from inside the script should not be validated as XHTML:
    [code]
    <script type="text/javascript">
    /*<![CDATA[*/
    //Javascript code here
    /*]]>*/
    </script>

    We can also use another version, both of these wrappers will work:
    [code]
    <script type="text/javascript">
    //<![CDATA[
    //Javascript code here
    //]]>
    </script>

    2: Another way of doing this is to remove the script from the page and store it in a .js file which will be called by our page like in the example from bellow:
    [code]
    <script type="text/javascript" src="thescript.js">
    //A comment here
    </script>

    In this example "thescript.js" is the script itself stored into an external .js file (minus the surroundig "SCRIPT" tags. Comments within the script tags are still allowed.

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      CSS (142)

    New

    Hot