Latest web development tutorials

HTML DOM Script character attributes

Script Object Reference Script Object

Examples

Get the character set used in external script files:

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

x The output is:

UTF-8

try it"

Definition and Usage

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

charset attribute specifies the character encoding of an external script files.

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the charset attribute.


grammar

Returns the charset attribute:

scriptObject .charset

Set the charset attribute:

scriptObject .charset= charset

Property Value

描述
charset 规定外部脚本文件的字符编码。

一些常用的值:

  • "ISO-8859-1" - 拉丁字母表的标准编码
  • "UTF-8" - Unicode 字符编码。与 ASCII 兼容

请参阅我们的 字符集参考手册 ,获得完整的字符集列表。

technical details

return value: String that represents the URL of an external script file. Returns the complete URL, including the protocol (such as http: //).


related articles

HTML Reference Manual: HTML <Script> charset attribute


Script Object Reference Script Object