Document.characterSet
只读属性返回当前文档的字符编码。该字符编码是用于渲染此文档的字符集,可能与该页面指定的编码不同。(用户可以重写编码方式。)
document.charset
和document.inputEncoding
属性是document.characterSet
的遗留别名。不要再使用它们。
语法
var string = document.characterSet
示例
<button onclick="alert(document.characterSet);">查看字符集</button> //返回当前文档的字符集,比如"ISO-8859-1" 或者 "UTF-8"
规范
规范 | 状态 | Comment |
---|---|---|
DOM characterSet |
Living Standard | 初始定义. |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
基本支持 | 45.0 | (Yes) | (Yes) | ? | ? | 9 (possibly earlier) |
字符集 |
Made read-only in 45 | (Yes) | 44 (44) | ? | ? | 9 (possibly earlier) |
Feature | Android | Android Webview | Edge | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|---|
基本支持 | 未实现 | 45.0 | (Yes) | (Yes) | (Yes) | ? | ? | ? | 45.0 |
字符集 |
? | ? | (Yes) | 44.0 (44) | 2.5 | ? | ? | ? | ? |