RE: validating JavaScript

At 2003-07-03T21:07+0100, Jake Brumby wrote:-

[Rearranged]
> >"The HTML specification does not cover JavaScript.

Correct.

> >                                                    However, the
> >Validator does not recognize JavaScript code from HTML

That is also correct - the validator does not include a JavaScript
interpreter.

> >                                                       and attempts
> >to "validate" it as HTML.

If some JavaScript occurs within an HTML document, then it is part of an
HTML document and should be valid as such. In HTML (but not XHTML), the
SCRIPT element has CDATA content, which means that most markup is not
recognised, but the start of an end tag ("</") is, and must not appear in
the content (because it ends it). (See below)

> >Is this correct?

[Bjoern Hoehrmann]
> What's the offending code?

> The offending code is below.
>
> BTW - am I correct in replying to www-validator@w3.org and should I

Yes.

> include previous threads below in this email? Thanks!

Including the relevant parts of the preceding discussion is useful to
provide context, but it seems more logical to keep the conversation in
chronological order.

> <SCRIPT Language = "JavaScript">

The language attribute is deprecated (though still allowed); HTML 4
requires there to be a type attribute. Unfortunately there is (still) no
correct MIME type for JavaScript, so you can't win whatever you do.

> 	document.write("<SCR" + "IPT Language = 'JavaScript' SRC = '" + wtl_loc + "'></SCR" + "IPT>");

!!!

The validator will have complained about the "</". That can easily be
fixed by saying "<\/" or splitting the string differently, and this at
least can probably only improve compatibility.


Tim Bagot

Received on Thursday, 3 July 2003 17:47:36 UTC