Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2008
    Location
    Blackpool, UK
    Posts
    176
    Thanks
    4
    Thanked 0 Times in 0 Posts

    W3C Validation Issue

    Hi Guys,

    I like to adhere to W3C standards compliant sites whenever I build them.

    However I have produced this one site where I need javascript for a certain aspect and basically one part of the javascript is not making the site compliant.

    As I am no expert in Javascript I do not know how to get the script to work in an external file so it is in the head tag and one part of the script which contains this greater than sign "<" and it will not validate because it wants it to be &lt; which it cannot be.

    Does anybody know how I can validate this page or if I provide the javascript code can someone show me how to make work as an external file.


    Cheers


    Dan

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    To make an external file, you just put all of the js code (except the <script> tags) into a new file. Use the file extension .js. Then link to it in your original file like so...

    Code:
    <script language="javascript" src="external.js"></script>
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts
    jeremywilken's way is best, but if you absolutely have to include the Javascript in the markup file, enclosing the script in CDATA tags will tell the validator to skip it:

    Code:
    <script type="text/javascript">
    <![CDATA[
    ...
    ]]>
    </script>
    matt | design | blog

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,701
    Thanks
    6
    Thanked 1,011 Times in 984 Posts
    You should still comment out the CDATA tags:

    Code:
    <script type="text/javascript">
    // <![CDATA[
    ...
    // ]]>
    </script>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •