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

HTML DOM Script src Property

Script src Property

Script Object Reference Script Object

Example

Get the character set of the externally referenced script file:

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

x The output result is:

UTF-8

Try it »


Definition and Usage

The charset property specifies the character encoding used in 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

property
charset Yes Yes Yes Yes Yes

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 that returns the character set used by the external script file.

    Script Object Reference Script Object