W3cubDocs

/DOM

Encoding API

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The Encoding API provides a mechanism for handling text in various character encodings, including legacy non-UTF-8 encodings.

The API provides two interfaces: TextDecoder and TextEncoder.

Interfaces

Tutorials & tools

  • A shim allowing to use this interface in browsers that don't support it.
  • StringView – a C-like representation of strings based on typed arrays.

Specifications

Specification Status Comment
Encoding Living Standard Initial definition.

Browser compatibilityUpdate compatibility data on GitHubUpdate compatibility data on GitHub

TextDecoder

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 38 ? 19
19
18
Implemented a slightly different version of the spec.
No 25 10.1
Available in workers 38 ? 20 No 25 10.1
TextDecoder() constructor 38 ? 19
19
18
Implemented a slightly different version of the spec.
No 25 10.1
decode 38 ? 19
19
18
Implemented a slightly different version of the spec.
No 25 10.1
encoding 38 ? 19
19
18
Implemented a slightly different version of the spec.
No 25 10.1
fatal ? ? ? ? ? 10.1
ignoreBOM ? ? ? ? ? 10.1
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 38 38 ? 19
19
18
Implemented a slightly different version of the spec.
? 10.1 ?
Available in workers 38 38 ? 20 ? 10.1 ?
TextDecoder() constructor 38 38 ? 19
19
18
Implemented a slightly different version of the spec.
? 10.1 ?
decode 38 38 ? 19
19
18
Implemented a slightly different version of the spec.
? 10.1 ?
encoding 38 38 ? 19
19
18
Implemented a slightly different version of the spec.
? 10.1 ?
fatal ? ? ? ? ? 10.1 ?
ignoreBOM ? ? ? ? ? 10.1 ?

TextEncoder

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 38 ? 19
19
18
Firefox 18 implemented an earlier and slightly different version of the specification.
No 25 10.1
Available in Web Workers 38 ? 20 No 25 10.1
TextEncoder() constructor 53
53
Does not accept parameters. Supports only utf-8 encoding.
38 — 53
Throws RangeError exception for unknown encoding types.
? 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.
No 25 10.1
encoding 38 ? 19
19
18
Firefox 18 implemented an earlier and slightly different version of the specification.
No 25 10.1
encode 38 ? 19
19
18
Firefox 18 implemented an earlier and slightly different version of the specification.
No 25 10.1
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 38 38 ? 19
19
18
Firefox 18 implemented an earlier and slightly different version of the specification.
? 10.1 ?
Available in Web Workers 38 38 ? 20 ? 10.1 ?
TextEncoder() constructor 38 38 ? 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.
? 10.1 ?
encoding 38 38 ? 19
19
18
Firefox 18 implemented an earlier and slightly different version of the specification.
? 10.1 ?
encode 38 38 ? 19
19
18
Firefox 18 implemented an earlier and slightly different version of the specification.
? 10.1 ?

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API