views:

74

answers:

3

I was looking at the W3C specs for the script tag, and I noticed you can specify VBScript and TCL as a language type. This is extremely new to me; I've only ever seen Javascript used with the script tag.

Why aren't other languages more commonly used, and is there a complete list of languages you can use within this tag?

+3  A: 

Why aren't other languages more commonly used, and is there a complete list of languages you can use within this tag?

Because javascript is supported by all browsers unlike VBS which is supported by only IE.

Note: The language attribute is deprecated now, use the type attribute only eg:

<script type="text/javascript">
...
</script>
Sarfraz
This is why I referred to it in my question as "language types". While not technically a correct phrase, I am aware that "language" is depreciated and wanted to convey that (though it's difficult). Nonetheless, this is an important reminder because the attribute is depreciated, yet I still see it occasionally...
Corey
+1  A: 

You can specify any language the browser can interpret, I imagine. At the moment, though, text/javascript is the only one supported across browsers.

VBScript is available in IE under some circumstances and thus (obviously) limited to Windows and that browser. It's not really an option if you want to build web sites that are to run across browsers and platforms. I think you can also use Windows Script Host scripts in IE, but I'm not familiar with the details.

Where have you seen an implementation of TCL? That would be interesting to see.

For completeness' sake, PHP understands <script language="php"> tags to specify the beginning of a block of PHP (reference). This doesn't really count in your list IMO as it's caught and interpreted on server side, and it only supports the deprecated language= syntax, but still.

Pekka
TCL? I've never seen it used anywhere... however, that W3C page has an example of it. That is what brought up my question; it's very strange.
Corey
@Corey can you post a link? I can't see it, I'm looking here: http://www.w3.org/TR/REC-html40/types.html#type-script
Pekka
Scroll down a bit: http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.2.3
Corey
@Corey oh, I must have mistyped while searching. Weird! I've never seen TCL support, at least not in a browser.
Pekka
It is weird. It makes me wonder if there's any documentation out there on what languages are supported in the tag, and what browsers support them.
Corey
+1 for that crazy php-hint o.0
oezi
+3  A: 

You can put anything you want in there. That's the whole point of MIME types.

The question is of course whether or not your user's browser can actually interpret it. But that's not really specific to the <script> element. My browser, for example, only understands CSS for stylesheets, others also understand XSLT. My browser only understands HTML, XHTML, HTML5, MathML and SVG for documents, others also understand PDF or don't understand MathML. My browser understands alpha-transparent PNGs, others don't. Before the GIF patent ran out, there were some browsers that didn't understand GIFs, while others paid the licensing fees (or used the patent illegally or were developed in jurisdictions where software patents are illegal) and did understand GIFs. Some browsers understand H.264 videos, others Theora.

In general, the only language that is guaranteed to be understood by all browsers, is ECMAScript 3rd Edition. Most browsers also understand some subset of JavaScript.

Many versions of Internet Explorer understand VBScript.

The CoffeeScript compiler can be compiled to ECMAScript and embedded into a website, so that you can use CoffeeScript in your page via the text/coffeescript MIME type.

There's a project called HotRuby, which is a YARV bytecode interpreter written in ECMAScript. It allows you to use text/ruby.

Microsoft has a project called Gestalt, which uses IronRuby and IronPython running on top of the DLR inside Silverlight to provide support for text/python and text/ruby (and presumably any language that can run on top of the DLR, e.g. Scheme, Smalltalk, PHP, Tcl.)

Mozilla had a project a while back called IronMonkey, I believe, which embedded multiple popular execution engines, such as MRI Ruby, CPython, Perl and others into Firefox, allowing the use of all those languages for browser scripting.

I remember reading somewhere that someone built a plugin for tcc (tiny C compiler) support, which would allow you to use text/c.

Just a couple of days ago, Miguel de Icaza (the creater of Mono) suggested that the ISO CLI should be added to the browser as a scripting platform, allowing you to use CIL bytecode for scripting via an application/cil MIME type.

Jörg W Mittag