Javascript Browser Window atob() Method

Introduction

Decode a base-64 encoded string:

Click the button to decode a base-64 encoded string.

View in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>
<p id="demo"></p>
<script>
function myFunction() {/*from  ww  w  .  java2  s. c o m*/
  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 atob() method decodes a base-64 encoded string.

This method decodes a string of data which has been encoded by the btoa() method.

atob(encodedStr);

Parameter Values

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

The atob() method returns a String representing the decoded string.




PreviousNext

Related