首页 > 解决方案 >

问题描述

  <script language="JavaScript1.2" ...
  <script language="JavaScript"  ...

Would those declarations make the JavaScript execution differ?

标签: javascripthtmlecma

解决方案


The language attribute is obsolete, browsers should only respect the type="" attribute.

On a historical note, the DOM API was (and ostensibly, still is) designed for many different languages and the W3C didn't endorse JavaScript in particular. Browsers have, at one point, supported:

  • JavaScript/ECMAScript
  • VBScript (Internet Explorer)
  • JScript (Microsoft's extensions to ECMAScript)
  • tcl (referenced by the HTML4.01 specification)
  • Rexx (IBM WebExplorer on OS/2)
  • Python (supported by Mosaic for a brief period)

So the idea was that different browsers were free to support whatever language they wanted, and it might be platform-specific if they executed scripts using some operating-system built-in language instead of it being embedded in the browser's own code-base (like how JScript/VBScript in Internet Explorer came from Windows' Active Scripting feature, it wasn't built-in to IE (until IE9), or tcl on Unix)

So on Internet Explorer I understand that IE would use the language="" attribute to look-up other Active Scripting languages if installed - so if you had a third-party script engine installed, like "ActivePerl" or even Fortran then that would also work in a <script> element in HTML, which is kinda crazy.

To answer your question directly (what possible values are there), the answer is "no-one knows": the attribute was deprecated back in 1998 in the HTML4.01 specification precisely because there was no standardised list of values for the language="" attribute:

https://www.w3.org/TR/html4/interact/scripts.html#adef-language

language This attribute specifies the scripting language of the contents of this element. Its value is an identifier for the language, but since these identifiers are not standard, this attribute has been deprecated in favor of type.


推荐阅读