Knowledge Walls
John Peter
Pune, Maharashtra, India
Base64 encode and decode using btoa() and atob() methods in javascript with example
11180 Views
Atob() and btoa() 
window.atob() method is used to encode string to base64.
window.btoa() method is used to decode base64 to string.

Syntax to use atob and btoa methods in Javascript
window.atob([Normal String])
window.btoa([Base64 encoded String])
Example
<html>
    <head>
        <script type="text/javascript">
            var myNameIs = "babu";

            document.getElementById("txtarea_1").value = window.atob(myNameIs);
            document.getElementById("txtarea_2").value = window.btoa(document.getElementById("txtarea_1").value);
        </script>
    </head>
    <body>
        <textarea id="txtarea_1"></textarea>
        <textarea id="txtarea_2"></textarea>
    </body>
</html>
Output 
Best Lessons of "Good Javascript Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details