TextEncoder() constructor returns a newly created utf-8 TextEncoder 对象。

句法

encoder = new TextEncoder();
					

参数

  • TextEncoder() takes no parameters since Firefox 48 and Chrome 53

注意 : Prior to Firefox 48 and Chrome 53, an encoding type label was accepted as a paramer to the TextEncoder object, since then both browers have removed support for any encoder type other than utf-8 , to match the spec . Any type label passed into the TextEncoder constructor will now be ignored and a utf-8 TextEncoder 将被创建。

异常

  • TextEncoder() throws no exceptions since Firefox 48 and Chrome 53

注意 : Prior to Firefox 48 and Chrome 53 an exception would be thrown for an unknown encoding type.

规范

规范 状态 注释
编码
The definition of 'TextEncoder()' in that specification.
实时标准 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
TextEncoder() 构造函数 Chrome 53 注意事项
53 注意事项
Does not accept parameters. Supports only utf-8 编码。
38 — 53 注意事项
抛出 RangeError exception for unknown encoding types.
Edge 79 注意事项
79 注意事项
Does not accept parameters. Supports only utf-8 编码。
Firefox 48 注意事项
48 注意事项
The constructor accepts an encoding type label argument, but the value is ignored. Only utf-8 encoding is supported.
38 — 48 注意事项
If the encoding type label argument is invalid, then a RangeError exception is thrown.
19 — 38 注意事项
If the encoding type label argument is invalid, then a TypeError exception is thrown.
18 注意事项
Firefox 18 implemented an earlier and slightly different version of the specification.
IE 不支持 No Opera 25 Safari 10.1 WebView Android 38 Chrome Android 38 Firefox Android 48 注意事项
48 注意事项
The constructor accepts an encoding type label argument, but the value is ignored. Only utf-8 encoding is supported.
38 — 48 注意事项
If the encoding type label argument is invalid, then a RangeError exception is thrown.
19 — 38 注意事项
If the encoding type label argument is invalid, then a TypeError exception is thrown.
18 注意事项
Firefox 18 implemented an earlier and slightly different version of the specification.
Opera Android ? Safari iOS 10.3 Samsung Internet Android 3.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

见实现注意事项。

另请参阅

元数据

  • 最后修改:
  1. 编码 API
  2. TextEncoder
  3. 构造函数
    1. TextEncoder()
  4. 特性
    1. encoding
  5. 方法
    1. encode()
    2. encodeInto()
  6. Related pages for Encoding API
    1. TextDecoder

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1