Script charset attribute

Definition and usage

charset Attribute sets or returns the script's Charset attribute Value.

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

Use the charset attribute when the character encoding of the external script file is different from the encoding of the HTML document.

Note:The charset attribute is only applicable to external scripts (it can only be used when the src attribute exists).

See also:

HTML Reference Manual:HTML <script> charset egenskab

HTML Reference Manual:HTML <script> tag

Example

Get the character set used in the external script file:

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

Try it yourself

Syntax

Return charset attribute:

scriptObject.charset

Set charset attribute:

scriptObject.charset = charset

Attribute value

Value Description
charset

Specifies the character encoding of the external script file.

Common values:

  • ISO-8859-1 - Latin alphabets' standard encoding
  • "UTF-8" - Unicode's tegnsætning. Kompatibel med ASCII.

Se voresTegnsæt henvisning,for at få en fuldstændig liste over tegnsæt.

Tekniske detaljer

Returværdi: Strengværdi, der repræsenterer tegnsættet, der bruges i eksterne skriptfiler.

Browserunderstøttelse

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support