If you are a website developer, it will be a really valuable action if you test whether your page passes the W3C validation standard. But why should you do this? If your pages pass W3C standard, it is often guaranteed that your pages will load quicker in modern web browsers and be easier to maintain. You can validate your pages directly from World Wide Web Consortium’s website. And the link is here: http://validator.w3.org.
We can write a JavaScript that can validate a page on given parameter. Below I have written a very simple JavaScript function to test a page’s web standard. But you can customize it according to your requirements. This kind of JavaScript function can be helpful when we have lots of pages and we need to check them one by one by just clicking a button. Now let us make a HTML page with a JavaScript function and we will give validator.html as its name. The page’s code is as below:
<html>
<head>
<title>W3C Web Standard Test</title>
<script language=”javascript” type=”text/javascript”>
function testMyPage(webpageLocation)
{
var url = ‘http://validator.w3.org/check?uri=’ + webpageLocation;
window.open(url, ”, ‘width=775, height=500, status=yes, resizable=yes, scrollbars=yes, location=yes’);
}
</script>
</head>
<body>
<input name=”Button” type=”button” value=”Test My Page” onclick=”testMyPage(‘www.wordpress.com’);” />
</body>
</html>
A new window opens with your given page location i.e. url as below:

Remember that the above window may not appear if you have a pop-up killer active. I suggest you turn off the pop-up killer program (if any) to test the code.
Now, if your page passes the validation, you will get a “This Page Is Valid XHTML 1.0 Transitional!” message. You will also get a congratulations message. If you want, you can use available options such as Show Source, Show Outline, Validate error pages, Clean up Markup with HTML Tidy etc. and revalidate the page.
If you want to test the current page, the validator.html page’s code will be as below:
<html>
<head>
<title>W3C Web Standard Test</title>
<script language=”javascript” type=”text/javascript”>
function testMyPage()
{
var url = ‘http://validator.w3.org/check?uri=’ + window.location.href;
window.open(url, ”, ‘width=775, height=500, status=yes, resizable=yes, scrollbars=yes, location=yes’);
}
</script>
</head>
<body>
<input name=”Button” type=”button” value=”Test My Page” onclick=”testMyPage();” />
</body>
</html>
What I have done here is — I just changed the webpageLocation parameter to window.location.href.
I must mention one thing and that is you cannot validate i.e. test web standard of any page that is located in your localhost.
Thus, this is very easy but important to validate our pages. I believe validation should be a part of professional website development although it takes some time. But it is a benchmark of the quality of your webpage.
OK. That is all I know.
May 5, 2008 at 2:43 pm
nice script,
have you tried validome.org?
May 5, 2008 at 3:52 pm
No Dani.
Since http://www.w3.org is the most authentic organization and it sets rule for web, I think using this site is enough for us web designers.