views:

47

answers:

3

The W3C HTML validator reports errors in lines which are inside script <script> tags. It's creating a lot of noise in the validation output. I can wrap my own script in CDATA but I have a lot of script added dynamically by third party controls.

Is there an HTML validator which can ignore everything in all <script> sections?

+1  A: 

Solution:

Remove the offending third party scripts while you're validating the HTML.

Michael Robinson
That's a hassle because there are many pages with many scripts.
Tony_Henrich
I guess that's my only choice.
Tony_Henrich
+2  A: 

Short Bad Answer

If you wish to continue to use the w3 validator but get rid of certain errors regarding html in script tags, you can comment your JavaScript as shown in this guide. This is clearly a hack and is not recommended.

Long Good Answer

The main point of a validator is to ensure your code keeps to standards. The documentation for the w3 validator points you to this guidance and the w3 itself has a guide on keeping html within script to standards.

Personally, I don't see a point of a validator that selectively ignores some standards. You can't know how a random browser is going to implement the w3 standard and just because the major browsers assumedly do not do anything wrong when ignoring errors embedded in script tags, that doesn't mean there aren't browsers that don't conform to standards more closely. Furthermore, there is no guarantee that major browsers won't change their implementation in the future to be closer to standards and thus break your code. It is better to fix the errors you are getting rather than ignore them.

Rupert
The whole point of my question is that I don't have control for some of the javascript produced. Technically in many situations, the JS has nothing to do with the HTML and the page layout. I am looking for for a more flexible HTML validator that looks at the HTML tags only. Maybe developed by someone in the same boat as me.
Tony_Henrich
Script tags and any HTML contents are covered in the standards from which HTML validators are written. Consequently, if you were to find an HTML validator which ignored script tags, it would not really be an HTML validator because it would be validating against a standard that hasn't been written. Unfortunately, I think this means you are unlikely to find a validator which avoids script tags. If you are using an XHTML DOCTYPE, have you considered changing it to a less stringent standard? This may make your script valid.
Rupert
A: 

It might be that Michael Robinson's suggestion or Rupert's Bad Short Answer can be done programmatically, though it might be painful to program.

If you can put a proxy or filter in front of your page that strips or modifies the script tags on the fly, the validator will not see the scripts.

Unfortunately, stripping the scripts is only easy if you've got valid XHTML, in which case of course you mightn't really need the validator...

Aside from the fact that this might be fun to try, I'm in favor of Rupert's Long Good Answer.

Don Roby