Latest web development tutorials

HTML DOM Script src attribute

Script Object Reference Script Object

Examples

Get an external script files referenced character sets:

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

x The output is:

UTF-8
try it"

Definition and Usage

charset attribute specifies the character encoding for use in external script file.

When an external script file character encoding and HTML document coding is not the same, it will use charset attribute.

Note: charset attribute applies only to external script (only when using the src attribute).


Browser Support

Attributes
charset Yes Yes Yes Yes Yes

grammar

Returns the charset attribute:

scriptObject.charset

Set the charset attribute:

scriptObject.charset=charset

Property Value

value description
charset The character encoding specified external script file.

Some common values:

  • "ISO-8859-1" - standard encoding of 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: String, returns the character set to use an external script file.

Script Object Reference Script Object