Script src Attribute

Script 对象参考手册Script Object

Example

Get the character set of the external referenced script file:

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

xThe output result is:

UTF-8
Try it »

Definition and Usage

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

The charset attribute is used when the character encoding in external script files is different from that in the HTML document.

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


Browser Support

Attribute
charset Yes Yes Yes Yes Yes

Syntax

Return the charset attribute:

scriptObject.charset

Set the charset attribute:

scriptObject.charset=charset

Attribute Values

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

Some common values:

  • "ISO-8859-1" - Standard encoding for the Latin alphabet
  • "UTF-8" - Unicode character encoding. Compatible with ASCII

Please refer to ourCharacter Set Reference Manualto get the complete list of character sets.


Technical Details

Return value: String, returns the character set used by the external script file.

Script 对象参考手册Script Object

Other extensions