Script characterProperty

Script 对象参考手册Script Object

Examples

Get the character set used in the external script file:

var x = document.getElementById("myScript").charset

xThe output is:

UTF-8

Try it Yourself »

Definition and Usage

The charset property sets or returns the value of the charset attribute of a script.

The charset attribute specifies the character encoding used by the external script file.

The charset attribute is used when the character encoding in the external script file differs from the encoding in the HTML document.

Note:The charset attribute only applies to external scripts (only when the src attribute is used).


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the charset attribute.


Syntax

Return the charset property:

scriptObject.charset

Set the charset property:

scriptObject.charset=charset

Property Values

Value Description
charset Specifies the character encoding of the external script file.

Some commonly used values:

  • "ISO-8859-1" - Standard encoding for the Latin alphabet
  • "UTF-8" - Unicode character encoding. Compatible with ASCII

See ourCharacter Set Reference Manual, for a complete list of character sets.

Technical Details

Return Value: A string, representing the URL of the external script file. Returns the full URL, including the protocol (such as http://).


Related Articles

HTML Reference Manual:HTML <script> charset attribute


Script 对象参考手册Script Object

Other Extensions