TextDecoder Web API | TextDecoder constructor
Last Updated :
04 Oct, 2019
Improve
In HTML there is a TextDecoder Interface of which we can create a TextDecoder object for the encoding specified in parameter.
Syntax:
html
Output:
html
Output:
decoder = new TextDecoder( utf-Label, option );Parameters: This constructor accepts two parameters which are mentioned above and described below:
- utf-Label: Label of the encoder in string format. It is "utf-8" as default.
- option: TextDecoderOptions dictionary which has a property fatal (It is a Boolean flag which indicates if the TextDecoder.decode() method should throw DOMException. It's default value is false.)
<!DOCTYPE html>
<html>
<head>
<title>
TextDecoder Web API | TextDecoder constructor
</title>
</head>
<body>
<center>
<h1 style="color:green;">
GeeksforGeeks
</h1>
<h2>TextDecoder constructor</h2>
<button onclick="gettextDecoder ();">
Get textDecoder object
</button>
<p id='textDecoder'></p>
<script type="text/javascript">
function gettextDecoder() {
var textDecoder1 = new TextDecoder("iso-8859-2");
console.log(textDecoder1);
}
</script>
</center>
</body>
</html>
- Before Click the button:
- After Click the button:
<!DOCTYPE html>
<html>
<head>
<title>
TextDecoder Web API | TextDecoder constructor
</title>
</head>
<body>
<center>
<h1 style="color:green;">
GeeksforGeeks
</h1>
<h2>TextDecoder constructor</h2>
<button onclick="gettextDecoder ();">
Get textDecoder object
</button>
<p id='textDecoder'></p>
<script type="text/javascript">
function gettextDecoder() {
var textDecoder1 = new TextDecoder();
console.log(textDecoder1);
}
</script>
</center>
</body>
</html>
- Before Click the button:
- After Click the button:
- Google Chrome 38
- Firefox 19
- Opera 25
- Safari 10.1