Re: Problem Validating SCRIPT Element with TYPE Attribute

On Sat, 21 Jun 2003, Alden A. Spafford wrote:

> Originally, the statement was
>   <script LANGUAGE=JavaScript>
> which did not pass validation because the attribute TYPE was omitted.

The presence of such an attribute has no practical impact _unless_ you
insert a TYPE attribute with a _wrong_ value. So is there any reason to
get upset by the validator's message?

> When I changed the statement to
>   <script TYPE=JavaScript>
> it passed validation but the variables in the JavaScript routine were
> undefined and caused browser errors when they were used with both Netscape
> 6.02 and Internet Explorer 5.5.

That's interesting, but the TYPE value is surely wrong. There is no such
media type defined, and it's not even of the type/subtype format. What
those browsers do is presumably that they think that the scripting
language is not any known language. If you omitted the attribute, they
would default to assuming the code is in JavaScript or its close relative.

> The compromise I came up with was this
>   <script LANGUAGE=JavaScript TYPE="">
> which is the current statement on the website.  This passes validation and the
> variables work with Netscape and Internet Explorer.  Of course, this just
> fakes out the validator.

It's less reliable a hack than simply omitting the TYPE attribute.

> But the Netscape and Internet Explorer browsers don't recognize TYPE.

They do. That's the problem. If you omit it, no problem; if you include it
with any value other than what pleases them, they refuse to understand
your script, thinking it's in some foreign language.

The HTML specifications tell us to use text/javascript for JavaScript, in
effect. This is not just fake, it is simply wrong by the authoritative
specification of Internet media types (MIME types) as defined in
RFCs 2045 through 2049. There is no registered media type text/javascript.
According to RFC 2046, "Any format without a rigorous and public
definition must be named with an 'X-' prefix".

To conclude, if you wish to comply with the syntax specified in HTML
recommendations, and thereby pass validation against a doctype specified
there, and you use a script element, you have to violate a widely
deployed, standards-track Internet protocol by the IETF.

-- 
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/

Received on Saturday, 21 June 2003 07:26:32 UTC