What language types are allowed in the HTML script tag?

只谈情不闲聊 提交于 2019-12-18 03:04:09

问题


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?


回答1:


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.




回答2:


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>



回答3:


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.



来源:https://stackoverflow.com/questions/2872037/what-language-types-are-allowed-in-the-html-script-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!