Forum Moderators: open

Message Too Old, No Replies

Validating JS script

WC3 founds tons of problems within JS script

         

henry0

10:07 pm on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use the transitional DTD
if I try to use the WC3 validator it results in many JS errors that I do not figure how to fix

now I used a trick; but is it a correct way of dealing with the problem?

I removed my JS scripts and use a library to call the scripts,
<script type="text/javascript" src= "library/indexdex.js"></script>
indeed now my page validates :)

any inputs or advice
thanks
regards
Henry

RonPK

10:40 pm on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My crystal ball tells me you should escape slashes in closing tags inside script on your page.

Example: in

document.write('<a href="some.html">go</a>');

the </ will be interpreted by the validator (and ancient or sgml-strict browsers) as an effort to close the <script>-tag. So you should escape it:

document.write('<a href="some.html">go<\/a>');

korkus2000

10:43 pm on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using a js library is perfectly valid and if you have reoccuring javascript a very good idea.

henry0

11:02 pm on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thank you
I will first try to make the scipt validating
if not I will use the library
for that script content a bunch of functions re-used by every page or most of them: the reload page for NN etc., swap img, img restore and find obj

g1smd

8:51 pm on Oct 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I like external javascript files. It gives search engine spiders less work to do. It allows the code to be cached and reused for other pages on the site.

MonkeeSage

10:39 pm on Oct 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I like external scripts better as well, since you can separate functions into several files, each named uniquely based on what they do (e.g., move.js, links.js, &c); just makes things a bit cleaner.

But, just FYI on inline scripts, if you comment your script blocks you shouldn't have a problem with the validators.

<script type="text/javascript">
<!--
//-->
</script>

The comment will cause the validator to skip from the opening script tag to the closing one w/o trying to evaluate ythe script inside them as HTML.

Jordan

g1smd

12:33 am on Oct 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Comment tags are OK to use in HTML 4.01 etc, but are not allowed in XHTML.

MonkeeSage

12:56 am on Oct 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For XHTML served as XML the comment syntax is:

<![CDATA[
]]>

Jordan

henry0

10:06 am on Oct 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



great thread
Thanks
now I understand why even with the regular comments I was not validating
however for the many advantages I will use the Library
and keep handy for small site with little JS the comment tag

regards

HEnry