Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why do this? <SCRIPT TYPE="text/javascript"

8 views
Skip to first unread message

Steve

unread,
May 6, 2008, 4:35:27 PM5/6/08
to
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

Thomas 'PointedEars' Lahn

unread,
May 6, 2008, 5:42:06 PM5/6/08
to
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$8300...@news.demon.co.uk>

Richard Cornford

unread,
May 6, 2008, 5:41:42 PM5/6/08
to
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.

Stevo

unread,
May 6, 2008, 6:02:06 PM5/6/08
to
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?

sheldonlg

unread,
May 6, 2008, 6:36:37 PM5/6/08
to
Steve wrote:

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

That's the form I always use. In Dreamweaver, if you type <script and
then a space, several choices come up and one is "type". Under that
there are a few choices, the first of which is "text/javascript".

Peter Michaux

unread,
May 6, 2008, 8:28:50 PM5/6/08
to
On May 6, 1:35 pm, Steve <tinker...@gmail.com> wrote:
> 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/".

That is strange. I've never had a problem. Is the "blah.js" file in
some strange character encoding?


> 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?

This is a bit of a tricky area. In mid 2006(?) the official type was
approved as "application/javascript" however everyone had been using
"text/javascript" and so there will be a transition period before
using "application/javascript" is the norm.

The type attribute is required by the HTML spec

http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.1

so if you want your page to validate as HTML

http://validator.w3.org/

you will need to include the type attribute.

-----------

Just in case you are new to validation, before you have a chance to
get excited about XHTML for the general web

http://www.thewebcreator.net/2007/04/16/why-you-should-be-using-html-401-instead-of-xhtml/
http://www.webdevout.net/articles/beware-of-xhtml

Also HTML 5 is almost surely the future of the web. XHTML just didn't
have a good chance with how strict it is and without support in
Internet Explorer, I guess.

Peter

RobG

unread,
May 6, 2008, 11:03:28 PM5/6/08
to

Thomas isn't referring to browsers, he's talking about
specifications. See Richard Cornford's reply to the OP.


--
Rob

Thomas 'PointedEars' Lahn

unread,
May 7, 2008, 6:19:34 PM5/7/08
to
Peter Michaux wrote:
> On May 6, 1:35 pm, Steve <tinker...@gmail.com> 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>
>>
>> It goes away if I remove the "text/".
>
> That is strange. I've never had a problem. Is the "blah.js" file in
> some strange character encoding?

That would not matter, unless we are talking a misconfigured local Web
server here which appears to be unlikely from the OP's description.
Instead, it is very likely that the OP only stored the JSP and not the
script, or they did not store it in the path where it belongs according to
the above `script' element.

>> What is <SCRIPT TYPE="text/javascript" used for? Is it necessary?
>
> This is a bit of a tricky area. In mid 2006(?) the official type was
> approved as "application/javascript" however everyone had been using
> "text/javascript" and so there will be a transition period before
> using "application/javascript" is the norm.

Will you please get that right eventually? RFC4329 cause the registration
of four media types for ECMAScript implementations, two especially for
JavaScript:

http://pointedears.de/scripts/test/mime-types/

> Also HTML 5 is almost surely the future of the web.

Wishful thinking.

> XHTML just didn't have a good chance with how strict it is and without support in
> Internet Explorer, I guess.

Quite the contrary. XHTML is continuously gaining speed on the Web despite
that because people use XML-compliant tools to generate it and serve it to
IE (and, unfortunately XHTML-compliant UA as well) as text/html instead.
While that practice surely is debatable, it is a development reality.

For example, we are mainly developing Plone-based Web sites (a decision made
by one of my predecessors that I have to live with). A Zope Page Template
(ZPT) that is required for efficient templating there (one wants to avoid
DTML for non-trivial templates) is an XML application, and if HTML code is
to be included it has to be XHTML or the template simply won't compile. So
I have to serve Appendix-C-compatible XHTML 1.0 Transitional as text/html
for those sites, knowing that I am relying on erroneous error-correction on
the part of user agents.

Laurent vilday

unread,
May 8, 2008, 9:31:47 AM5/8/08
to
Thomas 'PointedEars' Lahn a écrit :

> For example, we are mainly developing Plone-based Web sites (a decision made
> by one of my predecessors that I have to live with). A Zope Page Template

Obviously, it can't be your responsability to have choosen such a thing.

So obvious.

> (ZPT) that is required for efficient templating there (one wants to avoid
> DTML for non-trivial templates) is an XML application, and if HTML code is
> to be included it has to be XHTML or the template simply won't compile. So
> I have to serve Appendix-C-compatible XHTML 1.0 Transitional as text/html
> for those sites, knowing that I am relying on erroneous error-correction on
> the part of user agents.

Muahahaha, shoot yourself in the foot (bad tools, change tools). And you
dare being a dick when other ppl are saying they do the same as you do.

Pathetic

--
laurent

Peter Michaux

unread,
May 12, 2008, 9:59:38 PM5/12/08
to
On May 7, 3:19 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
> Peter Michaux wrote:

> > Also HTML 5 is almost surely the future of the web.
>
> Wishful thinking.

I'm not sure why you need to be so cryptic so frequently and require
me asking you to complete your explaination. Anyway...what do you mean
by "wishful thinking"? Do you mean you think XHTML is the future or
HTML 4.1 will remain the standard or that tag soup is the only way
etc.


> For example, we are mainly developing Plone-based Web sites (a decision made
> by one of my predecessors that I have to live with). A Zope Page Template
> (ZPT) that is required for efficient templating there (one wants to avoid
> DTML for non-trivial templates) is an XML application, and if HTML code is
> to be included it has to be XHTML or the template simply won't compile. So
> I have to serve Appendix-C-compatible XHTML 1.0 Transitional as text/html
> for those sites, knowing that I am relying on erroneous error-correction on
> the part of user agents.

Hard to believe you rely on user-agent forgiveness based on all the
elitist posturing you do frequently. It's good you will admit it,
however, rather than fake purity.

Peter

0 new messages