HTML <script> tag charset attribute
Examples
Define the character encoding used in the external script file:
<script type="text/javascript" src="myscripts.js" charset="UTF-8"</script>
Definition and Usage
The charset attribute specifies the character encoding used in the external script file.
If the character encoding of the external file is different from the encoding of the main file, the charset attribute must be used.
The default character encoding is ISO-8859-1.
src and charset attributes
For particularly long JavaScript programs or those used frequently, you may want to store these codes in a separate file. In this case, let the browser load that separate file through the src attribute.
The value of 'src' is the URL of the file containing this JavaScript program. The MIME type of the saved file should be application/x-javascript, but if the file extension is .js, it can also be properly processed by servers that are correctly configured.
For example, the following statement:
<script type="text/javascript" src="/codew3c.com/abc.js">....</script>
The example above tells browsers that support <script> to download the JavaScript program named abc.js from the server.
Important Note:Note that even though the <script> tag has no content, the ending </script> tag is also necessary.
The charset attribute, used together with the src attribute, tells the browser the character set used to encode this JavaScript program. Its value is the name of any ISO standard character set encoding.
Syntax
<script charset="value">
Attribute Value
Value | Description |
---|---|
character_encoding |
Character Encoding of External Script Files. Common character sets include:
To view all available character sets, please visit our Character Set Reference Manual. |