Is the script tag attribute type or language used?

Source: Internet
Author: User

A question was asked:

<script language = "JavaScript"><script type="text/javascript"><script>

What are the differences between the three tags? Golden Light Avenue entertainment city

Although it has been used for a long time, it has not been well understood. Here is a detailed description.

Check some documents, mainly for browser support issues. Both the type and language attributes can be used to specify the Script Type in the <SCRIPT> tag. The language attribute has been criticized in the HTML and XHTML standards. The two standards advocate the use of the type attribute. Unfortunately, the values of these two attributes are different.

You may occasionally see that the language value is VBScript (text/VBScript for type), indicating that the included script code is written in Microsoft Visual BASIC script.

Using JavaScript, you can also use the language value "javascript 1.1", indicating that the contained script statements can only be processed by Netscape 3.0 or an updated version. Netscape 2.0 only supports JavaScript 1.0 and cannot process scripts marked as "javascript 1.1.

To ensure normal execution of the script program, unless you use the VBScript and script encoder mechanisms supported by IE only, you should set the "type" attribute marked by the script to "JavaScript ", do not set the obsolete "Ange" attribute.

Each browser supports the "type" and "language" attributes, but the recognition and support for the set script language types vary:

  • When both "type" and "language" exist, all browsers should first identify the Script Type in the "type" attribute;
  • The IE browser actually supports JScript and VBSCRIPT script language identification and script encoder encryption;
  • Firefox Chrome safari Opera's specific recognition of "type" attribute values is different in width. Compared with chrome safari, the validation of attribute values is more relaxed, and Firefox is the most rigorous;
  • In the comparison of the "language" attribute value recognition width, chrome Safari is still the most loose among browsers, ie is the strictest, and Firefox is the same as opera;
  • In language encode comparison, only ie supports JScript. encoder and VBScript. encoder type settings are not supported by Firefox Chrome safari. In opera, the output value is generated only after the attribute value is fixed as the default Javascript script language.
<script language="javascript">function a() {b = "a";}a();alert(b);</script>

There is a problem with variables. Even if you declare a variable in the function as above, it will become a global variable.

If VaR is used, a problem occurs.

<script language="javascript">function a() {var b = "a";delete b;alert(b);}a();</script>

A is still displayed in the result.

To ensure normal execution of the script program, unless you use the VBScript and script encoder mechanisms supported by IE only, you should set the "type" attribute marked by the script to "JavaScript ", do not set the obsolete "Ange" attribute.

Is the script tag attribute type or language used?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.