From: Steve on
Hi;

I've being going through some legacy code on an old JSP site I have
been patching. I noticed that when I save the JSP down to my PC as an
HTML file I get this javascript error in IE 6 ( not in the latest
Firefox ):

"invalid character"

The problem traces back to this line of code:

<SCRIPT TYPE="text/javascript" SRC="abc/jsp/blah.js"></SCRIPT>

It goes away if I remove the "text/".

I have never seen a script tag with "TYPE" or "text/javascript"
used. Only "language = "javascript""

What is <SCRIPT TYPE="text/javascript" used for? Is it necessary?

Thanks in advance









From: Thomas 'PointedEars' Lahn on
Steve wrote:
> I've being going through some legacy code on an old JSP site I have
> been patching. I noticed that when I save the JSP down to my PC as an
> HTML file I get this javascript error in IE 6 ( not in the latest
> Firefox ):
>
> "invalid character"
>
> The problem traces back to this line of code:
>
> <SCRIPT TYPE="text/javascript" SRC="abc/jsp/blah.js"></SCRIPT>

Chances are a resource with the relative URI abc/jsp/blah.js simply does not
exist (because you have missed downloading it to the appropriate location in
the local filesystem), in which case the error message generated by the user
agent or the Web server does not constitute a syntactically correct program.

> It goes away if I remove the "text/".

Probably because the script is never loaded then.

> I have never seen a script tag with "TYPE" or "text/javascript" used.

Then you have seen either only Valid HTML 3.2, where the `script' _element_
has no attributes, or a lot of invalid HTML code.

> Only "language = "javascript""

But using that ranges from being deprecated to invalid nowadays.

> What is <SCRIPT TYPE="text/javascript" used for?

To include code written in and for client-side ECMAScript implementations.

> Is it necessary?

The `type' attribute of the `script' element is required, and a MIME media
type is required as its value, since HTML 4.0:

http://www.w3.org/TR/REC-html40/interact/scripts.html#edef-SCRIPT


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7(a)news.demon.co.uk>
From: Richard Cornford on
Steve wrote:
> I've being going through some legacy code on an old JSP
> site I have been patching. I noticed that when I save
> the JSP down to my PC as an HTML file I get this
> javascript error in IE 6 ( not in the latest
> Firefox ):
>
> "invalid character"
>
> The problem traces back to this line of code:
>
> <SCRIPT TYPE="text/javascript" SRC="abc/jsp/blah.js"></SCRIPT>

That error usually means that the SRC's URL does not refer to an
existing resource, and the resulting 404 error page is HTML which when
interpreted as javascript source code will produce one form of syntax
error or another.

> It goes away if I remove the "text/".

Yes, you have then prevented the browser from recognising the type of
script and so it is not passing it into its javascript interpreter and
so not finding the HTML that it is receiving erroneous when interpreted
as javascript.

> I have never seen a script tag with "TYPE" or "text/javascript"
> used.

Then you had best leave web development to someone with a little more
relevant experience.

> Only "language = "javascript""

The language attribute of SCRIPT elements is deprecated in HTML 4 and
not usable with strict (x)HTML DTDs.

> What is <SCRIPT TYPE="text/javascript" used for?

The type attribute is required in valid HTML and is used to declare the
type of script language used.

> Is it necessary?

For valid mark-up it is required, in a purely practical sense it is not
necessary. Most browsers will default to assuming javascript is the type
of script language to use unless told something else, and most browsers
can cope with defective/non-valid (a.k.a. 'tag soup') HTML mark-up to
some degree or another. On the other hand, using mark-up that it at
minimum structurally valid can avoid issues when attempting to script
the resulting DOM, and having formally valid mark-up is one way of
guaranteeing that the mark-up is structurally valid.

Richard.

From: Stevo on
Thomas 'PointedEars' Lahn wrote:
> Steve wrote:
>> Only "language = "javascript""
> But using that ranges from being deprecated to invalid nowadays.
> PointedEars

Which browser(s) treat language="javascript" as invalid?