|
I know very little about JavaScript - apart from the non-validating pages, slow-loading times, evil pop-ups, malicious code and so on - just enough to realize I should probably use it sparingly, or not at all. At any rate, whenever I use a script for newsfeeds, or to achieve an effect of some sort, it usually has errors. Fortunately, most of the time it looks worse than it is. The following is the JavaScript code for a newsfeed with 13 errors and 15 warnings in it; although the first 2 errors are the only ones that matter in this case:
View and validate here...
#1 Error. Line 38 column 20: there is no attribute "language".
#2 Error. Line 38 column 83: general entity "table_bgcolor" not defined and no default entity.
1. Proper Script Declaration in XHTML Strict:
The first error refers to <script language="Javascript" src="...">. Since "language" is not a recognized attribute of xhtml strict, you need to replace this:
with this:
(Just like with CSS you have: <style type="text/css">, so it is with JavaScript: <script type="text/javascript">)
2. Unencoded Ampersands in XHTML Strict:
The second error refers to unencoded ampersands which are these: &. Usually, anytime you have an ampersand symbol appearing in the code (even inside a URL) or if you just want it to appear as text, for that matter; it must be followed by amp; (including the semi-colon) to escape being parsed as code. So it should look like this: &
All that needs to be done with our newsfeed now is to go through the code and escape all the ampersands - simple enough, but can be quite tedious when working with long scripts. Fortunately, correcting these two errors also takes care of the remaining ones.
3. Uppercase Lettering in XHTML Strict:
Although it doesn't really apply in this case, uppercase lettering in xhtml strict is also a no-no, so all lettering needs to be done in lower-case. With these things done, the newsfeed code validates xhtml strict just fine!
Undoubtedly, there's lots of JavaScript examples with other errors, but using this simple 3-point checklist as a starting point, you should eliminate most, if not all the errors and warnings you're getting from the Validator:
- All lowercase lettering
- Proper JavaScript declaration: <script type="text/javascript">
- Escape the ampersands: &
The cleaned up and validating code should look like this:
View and validate here...
P.S. - Why JavaScript authors or the programmers of JavaScript code generators don't eliminate these defects at the source escapes me - seems like it would be a simple thing to correct (hint, hint)?
|