Javascript examples for Browser Object Model:Window btoa
The btoa() method encodes a string in base-64.
Parameter | Description |
---|---|
str | Required. The string to be encoded |
A String, representing the base-64 encoded string
The following code shows how to Encode a string in base-64:
<!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>