TextDecoder()
The TextDecoder() constructor returns a newly created
TextDecoder object for the encoding specified in parameter.
If the value for utfLabel is unknown, or is one of the two values leading to a
'replacement' decoding algorithm ( "iso-2022-cn" or
"iso-2022-cn-ext"), a RangeError is thrown.
Syntax
new TextDecoder(utfLabel, options);
Parameters
utfLabelOptional-
Is a
DOMString, defaulting to"utf-8", containing the label of the encoder. This may be any valid label. optionsOptional-
Is a
TextDecoderOptionsdictionary with the property:fatal-
A
Booleanflag indicating if theTextDecoder.decode()method must throw aTypeErrorwhen an coding error is found. It defaults tofalse.
Example
var textDecoder1 = new TextDecoder("iso-8859-2");
var textDecoder2 = new TextDecoder();
var textDecoder3 = new TextDecoder("csiso2022kr", {fatal: true}); // Allows TypeError exception to be thrown.
var textDecoder4 = new TextDecoder("iso-2022-cn"); // Throw a RangeError exception.
Specifications
| Specification |
|---|
| Encoding # ref-for-dom-textdecoder① |
Browser compatibility
BCD tables only load in the browser
See also
- The
TextDecoderinterface it belongs to.