[Javascript] type="javascript1.2" vs language="javascript1.2"

Dave Transom subscribed at livedonkey.net
Thu Sep 11 19:13:25 CDT 2003


Hi All,

I've reached a bit of a dilemma while trying to adhere to current web
standards. The problem being that the language of a script not actually
having an effect when the type attribute is present in a script tag.

In the W3C's specification for XHTML1.0 Transitional, the language attribute
of the "script" tag has been depreciated in favour of the "type" attribute.

However when trying to target javascript 1.2 and xhtml compliance, I made
the following observations (using ie6, nn4.x and nn7.1):
==============================
1) <script type="text/javascript1.2"> is not a valid content type and
defaults to javascript 1.0.

2) <script type="text/javascript" language="javascript1.2"> gets processed
as javascript 1.0, since its "type" is "text/javascript" (the order of the
attributes doesn't matter either, type still takes preference).

3) <script language="javascript1.2"> gets processed as javascript 1.2, but
without the "type" attribute is not xhtml compliant.
==============================

Personally, I prefer the testing of methods etc for compatibility e.g.
"if( !document.getElementsByTagName ) return false;", so the language
version doesn't really matter (unless you are trying to target a specific
version of javascript, for instance, Array.splice() returns differently in
1.2 and 1.3), but for older scripts being used, that don't use method
testing and rely on the language version of the script tag to provide the
compatibility, there doesn't appear to be an standard option.

I can imagine making a quick script to test the browsers javascript version,
and then document.write the javascript1.2 script tag (with external src
file) to the browser if appropriate, but surely there must be other options?

Has anyone delved into this situation before? And better still, has anyone
got a standards compliant solution for it?

Hope that gets you brains out there thinking :)


Regards,
Dave Transom





More information about the Javascript mailing list