The atob()
method decodes a base-64 encoded string.
atob |
Yes | Yes | Yes | Yes | Yes |
window.atob(encodedStr)
Parameter | Description |
---|---|
encodedStr | Required. The string which has been encoded by the btoa() method |
The decoded string
The following code shows how to decode a base-64 encoded string.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!-- w w w . j a va2s . c om-->
<p id="demo"></p>
<script>
function myFunction() {
var str = "Hello World!";
var enc = window.btoa(str);
var dec = window.atob(enc);
var res = "Encoded String: " + enc + "<br>" + "Decoded String: " + dec;
document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>
The code above is rendered as follows: