W3C Validator Javascript

I used to like some small unobtrusive links to the various W3C html and css validators at the bottom of my pages. Instead of mainting these links by hand I decided to write some litte Java for the task. The solution I came up with is W3C compliant in that browsers not capable of Javascript simply won’t display the links.

Here is the code for the Java function which I placed in the

validator.js
file:

  function validator()
  { 
      var url = 'Check this page for ' +
                '<a href="http://validator.w3.org/checklink?uri=' +
                location.href + "'>dead links</a>, ' +
                '<a href="http://validator.w3.org/check?uri=' +
                location.href + '">sloppy html</a>, or a ' +
                '<a href="http://jigsaw.w3.org/css-validator/validator?uri=' +
                location.href + '">bad style sheet</a>.';
      document.write(url);
  } 

The function is included in the html page by placing the following between the

<head>
and
</head>
tags:
  <script src="validator.js" type="text/javascript">
  </script>

Now that this function is available in the page, it is used on the page by placing this code in the body of the page:

  <script type="text/javascript">
    <!-- // For browsercompatibility
    validator();
     // -->
  </script>

While this little script worked quite well, it had been replaced by some php code for a while. With WordPress it has really become obsolete for this site.

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>