Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Script character Property

Script character Property

Script Object Reference Script Object

Example

Get the character set used in an external script file:

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

x The output is:

UTF-8

Try it »


Definition and Usage

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

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

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

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


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the charset property.


Syntax

Return the charset property:

scriptObject

.charset

Set the charset property:

scriptObject

.charset=

charset

Attribute values

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

Some common values:

  • "ISO-8859-1" - The standard encoding for the Latin alphabet
  • "UTF-8" - Unicode character encoding. Compatible with ASCII
  • See our character 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