Window btoa() Method - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window btoa

Description

The btoa() method encodes a string in base-64.

Parameter Values

Parameter Description
str Required. The string to be encoded

Return Value:

A String, representing the base-64 encoded string

The following code shows how to Encode a string in base-64:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {/*ww  w.  j av  a 2s  .  co  m*/
    var str = "Hello World!";
    var enc = window.btoa(str);

    var res = "Encoded String: " + enc;
    document.getElementById("demo").innerHTML = "The original string: " + str + "<br>" + res;
}
</script>

</body>
</html>

Related Tutorials