jQuery W3C-Validator Icons (Text, whatever) Plugin

Categories: Featured, JavaScript and jQuery
Written By: admin


If you see gramatical mistakes please leave me a comment so I can improve

Did you ever created a website that validated according to W3C, placed a “valid” Icon / Text on your site and after some days / weeks / months you had to notice that the site became invalid? To me this happens pretty often, mainly when I have to create a CMS based website for a customer. Everything validates perfectly until the customer begins to mess it up with his own HTML. Of course the “valid” Icon then loses his usefulness.

For a new project I was looking out for a script that would validate the current site in the background and only show a “valid” Icon if the current site passed validation. So I searched for such a solution but didn’t find anything useful and ended up writing it myself.
I came up with a jQuery Plugin that does exactly what I wanted it to do: it validates the current site (using the online W3C Validator), checks the result and shows then some HTML (”valid” Icon, Text or whatever) for both possible results (valid, invalid).

The Plugin consists of a JavaScript file (what you would call the ‘plugin’) and a PHP file. Latter does the validation (URL file access can be disabled, it’s done with cURL and should work for everyone).
Here’s how you use the plugin:

jQuery("#validHTML").w3cValidator({
	parserLocation: "path/to/w3cValidator.php",
	URL_isValid: '<a class="standardLink" href="http://validator.w3.org/check?uri=referer">valid HTML</a>', /* optional */
	URL_isInvalid: '' /* optional */
});

And here’s a demo (take a look at your Firebug console):
This Blog has:
 
Normally you wouldn’t tell your visitors that the current site has some errors ;)
To see a site that validates you can go to the this project of mine and take a look at the footer (and here a specific page from the same project that doesn’t validate).
 
Well, I think the plugin is pretty self-explanatory, so I won’t write a novel about it. If you think you could use it somewhere, just download the two plugin files, upload them to your server, insert the javascript file into you markup

<script style="text/javascript" src="path/to/jquery.w3cValidator.js"></script>

call the plugin

jQuery("#validHTML").w3cValidator({
	parserLocation: "path/to/w3cValidator.php",
	URL_isValid: '<a class="standardLink" href="http://validator.w3.org/check?uri=referer">valid HTML</a>', /* optional */
	URL_isInvalid: '' /* optional */
});

and you’re done! (But don’t forget that it is a Plugin and you’ll need jQuery to use it.)

If you want change the output just stick with “URL_isValid” and “URL_isInvalid” which are allowed to contain any HTML.
 
 
 
Changelog:
13/Aug/2008 - Minor change to the PHP file. added urlencode();

6 Responses to “jQuery W3C-Validator Icons (Text, whatever) Plugin”

  1. Paul Says:

    Ha, I found this yesterday though another website and though, jeez, that was my idea that I haven’t clue how to do awhile back - then I check my mint stats and see a clickthrough from Bedrich Rios site and saw your comment, so that is awesome work! And isn’t the net a darn small place! :D

  2. admin Says:

    Oh hey Paul!
    I’m glad you liked the plugin! (hehe, and the web’s kind of tiny if you put away all that myspace [snd similars] stuff ;) )

  3. Brian Says:

    Hey , maybe you can extend plugin to also use the W3C CSS validator?

  4. admin Says:

    Hey Brian,
    Hm, this would be very easy - i’ll do it this weekend ;)

  5. Rahul Says:

    This is quite cool. Hoping to download the CSS validator as well. ;)

  6. Vince Delmonte Says:

    Not that I’m impressed a lot, but this is more than I expected when I found a link on Digg telling that the info here is awesome. Thanks.

Leave a Reply

Featured & Popular Articles