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

Use of type and/or language in script-tag

P: n/a
Hi group,

I am a bit cconfused with the different tags I encounter to start a script.
I used to use: language="Javascript"

Nowadays I use: type="text/javascript"

I did see some javascript1.2 (i think) too, but never used that.

But when I let my favorite editor (Eclipse) do some codecompletion I get:
<script language="JavaScript" type="text/javascript"
src="jsfile.js"></script>

Forget about the src for a moment.
I see 2 definition in the same tag.

Is that ok?
And on a sidenote: Am I safe when I use the modern type="text/javascript"
only? The answer probably depends on the browser.

Where can I find some coherent information?
Some overview with browsers and javascripttags and such.

I did find some information already but I am looking for a overview/advise.

Thanks for your time!

Regards,
Erwin Moller
Jul 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a


Erwin Moller wrote:
I am a bit cconfused with the different tags I encounter to start a script.
I used to use: language="Javascript"

Nowadays I use: type="text/javascript"

I did see some javascript1.2 (i think) too, but never used that.

But when I let my favorite editor (Eclipse) do some codecompletion I get:
<script language="JavaScript" type="text/javascript"
src="jsfile.js"></script>

Forget about the src for a moment.
I see 2 definition in the same tag.

Is that ok?
And on a sidenote: Am I safe when I use the modern type="text/javascript"
only? The answer probably depends on the browser.


Well, <script> is an element in HTML 4, you can find the syntax for HTML
4 on http://www.w3.org/TR/html4/interact/....html#h-18.2.1 where you
should find that the type attribute is mandatory while the language
attribute is deprecated. Thus if you want to author your HTML pages
according to the HTML 4 standard then you at least need
<script type="content type for your script language">
However there is no MIME type registered for JavaScript as far as I know so
<script type="text/javascript">
is what is common use but nothing standardized. Indeed some
implementations for script in SVG or XML pages use or at least allow
type="text/ecmascript".
As for HTML pages and browsers I think you are safe with
<script type="text/javascript">
modern browsers like IE5+, Netscape 6/7, Opera 7 support that and older
ones like Netscape 4 might not but default to assuming script is
JavaScript anyway.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a
On Thu, 19 Feb 2004 10:12:59 +0100, Erwin Moller
<si******************************************@spam yourself.com> wrote:
I am a bit cconfused with the different tags I encounter to start a
script.
I used to use: language="Javascript"
Bad.
Nowadays I use: type="text/javascript"
Very good.
I did see some javascript1.2 (i think) too, but never used that.
Oh so wrong! Specifying a version seems to cause odd parsing rules to be
invoked (for example, = meaning assignment *and* equal to[1]) and limiting
the available methods and properties that are available. Most people don't
understand the consequences of either.
But when I let my favorite editor (Eclipse) do some codecompletion I get:
<script language="JavaScript" type="text/javascript"
src="jsfile.js"></script>
My editor used to do that, but I fixed it. I don't know if you can in
Eclipse - look in the preferences.
Forget about the src for a moment.
I see 2 definition in the same tag.

Is that ok?
The language attribute is deprecated. Last week, I went on a trek through
the older HTML specifications to see exactly when this deprecation
occurred. This is what I found:

In version 2.0, there was no SCRIPT element.
In version 3.2, there were no formal attributes to the SCRIPT element.
In version 4.0, all of the current attributes were present, and language
was already deprecated.

What I conclude from that is that the language attribute was proprietary
(at a guess, probably Netscape) and was never a recommended part of the
HTML language. When the need to specify the scripting language was
identified, it was determined that the language attribute was inadequate
(values were inconsistent) so it was added to the specification, but at a
deprecated status. The type attribute, using MIME type values, was
recommended in its place. As such, it has never really been OK to use it,
apart from in the early days of version 4.0 and earlier, though strictly
for backward-compatibility purposes only.

[If I am totally off the mark, or if there is further information on this
subject, I would be interested in hearing it.]
And on a sidenote: Am I safe when I use the modern type="text/javascript"
only? The answer probably depends on the browser.
The type attribute is not modern. It first appeared in v4.0, which was
released just over six years ago. You will not encounter any problems
using it[2].
Where can I find some coherent information?


Just follow the specifications. In everything, that is the best you can
do. If there is an identified problem (such as IE's general lack of
standards support), then you should embark on a workaround for that
situation. I don't think it is, or should be, the author's job to cope for
broken or obsolete browsers (unless it is really in the interest of the
project).

That would be my assessment. Not normative, nor necessarily recommended,
by any stretch of the imagination.

Mike
[1] Mentioned by Randy Webb in an off-topic (at the time) discussion with
Richard Cornford and Lasse Nielsen.
[2] Even if a browser doesn't understand type, it is fairly guaranteed
that the browser will default to JavaScript anyway.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3

P: n/a
Thanks a lot Mike!

(offers Mike a virtual beer)

You clarified that tricky stuff quite nicely and at a level somebody who
didn't dive into it for a week (=me) can understand. :-)

Darn, by the way, I called something 6 years old 'modern'.
I guess I am getting old. :P

Thanks for your time!

Regards,
Erwin Moller

Jul 20 '05 #4

P: n/a
Thanks for explaining that Martin!

Regards,
Erwin Moller
Jul 20 '05 #5

P: n/a
On Thu, 19 Feb 2004 15:30:56 +0100, Erwin Moller
<si******************************************@spam yourself.com> wrote:
Thanks a lot Mike!

(offers Mike a virtual beer)
Teetotal I'm afraid, but it's the thought that counts. :)
You clarified that tricky stuff quite nicely and at a level somebody who
didn't dive into it for a week (=me) can understand. :-)
I would like to remind you (for my sake as much as yours) that that was
mainly conjecture. I couldn't really find anything concrete. The
discussions about the language attribute either occurred behind closed
doors, or on the public mailing list[1] and the last time I tried to
search that, the engine rolled over and died, so I won't be trying again
in a hurry.

I'm hoping that someone else will either confirm my analysis (either
explicitly or through silence), or correct it. In any case, the debate
should be over historical accuracy, or lack thereof. The main theme should
still be the same: use type and avoid language.
Thanks for your time!


You're very welcome.

Mike
[1] By that, I mean there was nothing in the specification notes.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #6

P: n/a
JRS: In article <op**************@news-text.blueyonder.co.uk>, seen in
news:comp.lang.javascript, Michael Winter <M.******@blueyonder.co.invali
d> posted at Thu, 19 Feb 2004 13:04:08 :-
[2] Even if a browser doesn't understand type, it is fairly guaranteed
that the browser will default to JavaScript anyway.


Unless the previous script on the page was not javascript (e.g.
VBscript).

I've not yet found anything in VB that looks useful for a mainly-JS
page, but a bit of JS could be used in a VB page for getTimeZoneOffset()

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #7

P: n/a
Erwin Moller wrote:
But when I let my favorite editor (Eclipse) do some codecompletion I get:
<script language="JavaScript" type="text/javascript"
src="jsfile.js"></script>

Forget about the src for a moment.
I see 2 definition in the same tag.

Is that ok?


I presume you are writing about the "JavaScript *" templates of
the PHPeclipse plugin for eclipse, which is the only editor plugin
that I know of to do code completion and thus I happen to use, too.
If that is the case, you can change these templates with Window,
Preferences, PHP, Templates, <script, Edit, ..., OK, OK.
HTH & HAND

PointedEars
Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.