W3C Validator Javascript

February 9, 2004 @ 11:39 pm

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.

No Comments

No comments yet.

RSS 2.0 feed for comments on this post.

Sorry, the comment form is closed at this time.