Script tag attribute type and language use selection _javascript tips

Source: Internet
Author: User
Tags script tag

Be asked a question:

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

What is the difference between the use of these three labels?
Although it has been used, but also did not make it clear, here detailed description.
Check out some information, mainly browser support issues. Both type and language properties can be used to specify the type of script in the <script> label. The language attribute is criticized in the HTML and XHTML standards, which promote the use of the type attribute in the two standards. Unfortunately, the values for these two properties are not the same.

You may occasionally see the value of language as VBScript (Text/vbscript for type), indicating that the included scripting code was written in Microsoft Visual Basic script.

With JavaScript, you can also use the language value "JavaScript 1.1", which means that the included script statement can only be handled by Netscape 3.0 or later. Netscape 2 only supports JavaScript 1.0, and cannot handle scripts labeled "JavaScript 1.1".


To ensure that the script executes properly, the "type" property of the script tag should be set to "JavaScript" and not to set the deprecated "Languang" unless you deliberately use the VBScript and script encoder mechanism only supported by IE. E "property.

Browsers support both the "type" and "language" properties themselves, but the scripting language types that are set are different in recognition and support:

    • When both "type" and "language" exist, all browsers prioritize the type of script within the "type" attribute;
    • The IE browsers actually support JScript and VBScript script language markings and script encoder encryption;
    • Firefox Chrome Safari Opera has an inconsistent recognition of the "type" attribute value, which is more relaxed than the value correctness of Chrome safari, and the most stringent for Firefox;
    • In the "Language" attribute value recognition latitude comparison, browsers in the browser is still the most relaxed, IE most stringent, Firefox and Opera flat;
    • Language Encode comparison, only IE support Jscript.encoder and Vbscript.encoder type settings, Firefox Chrome Safari does not support, Opera is the property value is fixed to the default Javas The output value is only available after the Cript script language.
<script language= "javascript" > 
function A () { 
b = "a"; 
} 
A (); 
alert (b); 

There is a problem with variables, even if you declare a variable as above in a function, it becomes a global variable.
If you use the VAR statement there will be a problem.

<script language= "javascript" > 
function A () { 
var b = "a"; 
Delete B; 
alert (b); 
} 
A (); 

The result will still pop a.
to ensure that the script program works correctly, you should set the script tag's "type" property to "JavaScript" and do not set an abandoned "Lan" unless you deliberately use the VBScript and script encoder mechanism only supported by IE. Guange "property.

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.