Usage of charset attribute of script tag

Source: Internet
Author: User

Definition and usage
The charset attribute specifies the character encoding used in an external script file.

If the character encoding in an external file is different from that in the main file, the charset attribute is used.

The default character encoding is the ISO-8859-1.
Src and charset attributes
For a particularly long JavaScript program or a program that is often used repeatedly, you can store the code in a separate file. In this case, let the browser load the individual file through the src attribute.

The src value is the URL of the file containing the JavaScript program. The MIME type of the saved file should be application/x-javascript. However, if the file name is suffixed with. js, it can be properly processed by the server correctly configured.

For example, the following statement:

<Script type = "text/javascript" src = "/w3school.com.cn/abc.js">... </script>
The example above tells the browser that supports <script> to download the JavaScript program named abc. js from the server.

Important: although the <script> tag has no content, the end </script> tag is also required.

The charset attribute is used with the src attribute to tell the browser to encode the character set of this javascript program. Its value is the name of any ISO standard character set encoding.
Instance
Define the character encoding used in the external script file:

<Script type = "text/javascript" src = "myscripts. js" charset = "UTF-8"> </script>
TIY
Syntax
<Script charset = "value">
Attribute Value
Value description
Character_encoding the character encoding method of the external script file. Common Character sets include:

UTF-8-Unicode character encoding
Character encoding of the ISO-8859-1-Latin alphabet
To view all available character sets, visit our character set reference manual.

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.