Javascript Reference - Window atob() Method








The atob() method decodes a base-64 encoded string.

Browser Support

atob Yes Yes Yes Yes Yes

Syntax

window.atob(encodedStr)

Parameter Values

Parameter Description
encodedStr Required. The string which has been encoded by the btoa() method




Return Value

The decoded string

Example

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: