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

S

Steve

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
 
R

Richard Cornford

Steve said:
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.
 
T

Thomas 'PointedEars' Lahn

Steve said:
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
 
P

Peter Michaux

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
 
R

RobG

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

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

Thomas 'PointedEars' Lahn

Peter said:
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.
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.


PointedEars
 
L

Laurent vilday

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
 
P

Peter Michaux

Peter Michaux wrote:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top