Window atob() Method - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window atob

Description

The atob() method decodes a base-64 encoded string which has been encoded by the btoa() method.

Parameter Values

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

Return Value:

A String, representing the decoded string

The following code shows how to Decode a base-64 encoded string:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from w  w  w  .  j a  v a2 s  .  c  om*/
    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>

Related Tutorials