Script characterProperty
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
![]()
![]()
![]()
![]()
![]()
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:
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
Other Extensions
Script Object