By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,795 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,795 IT Pros & Developers. It's quick & easy.

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

P: n/a
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



Jun 27 '08 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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/inte...ml#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, <f8*******************@news.demon.co.uk>
Jun 27 '08 #2

P: n/a
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.

Jun 27 '08 #3

P: n/a
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?
Jun 27 '08 #4

P: n/a
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".
>
What is <SCRIPT TYPE="text/javascript" used for? Is it necessary?

Thanks in advance


Jun 27 '08 #5

P: n/a
On May 6, 1:35 pm, Steve <tinker...@gmail.comwrote:
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/inte....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...tead-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
Jun 27 '08 #6

P: n/a
On May 7, 8:02 am, Stevo <n...@mail.invalidwrote:
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?
Thomas isn't referring to browsers, he's talking about
specifications. See Richard Cornford's reply to the OP.
--
Rob
Jun 27 '08 #7

P: n/a
Peter Michaux wrote:
On May 6, 1:35 pm, Steve <tinker...@gmail.comwrote:
>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.
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, <f8*******************@news.demon.co.uk>
Jun 27 '08 #8

P: n/a
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
Jun 27 '08 #9

P: n/a
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
Jun 27 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.