Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What language types are allowed in the HTML script tag?

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?

like image 659
Corey Avatar asked May 20 '10 08:05

Corey


People also ask

What scripting languages can be used in HTML?

The default scripting language Examples of values include "text/tcl", "text/javascript", "text/vbscript". In the absence of a META declaration, the default can be set by a "Content-Script-Type" HTTP header.

What is type in script tag in HTML?

The type attribute specifies the type of the script. The type attribute identifies the content between the <script> and </script> tags.

What language is script tag?

The <script> tag is used to embed a client-side script (JavaScript). The <script> element either contains scripting statements, or it points to an external script file through the src attribute.

What are different types of script tags?

async: It is used to specify the script is executed asynchronously. charset: It is used to specify the character encoding used in an external script file. defer: It is used to specify that the script is executed when the page has finished parsing. src: It is used to specify the URL of an external script file.


2 Answers

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.

like image 85
Jörg W Mittag Avatar answered Sep 23 '22 13:09

Jörg W Mittag


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> 
like image 25
Sarfraz Avatar answered Sep 19 '22 13:09

Sarfraz