w3resource logo

JavaScript window Object - btoa Method

JavaScript window Object : btoa() Method


Seondary Nav


The btoa() method of window object is used to convert a given string to a encoded data (using base-64 encoding) string.


Implemented in JavaScript 1.2




string-to-encode : String to be encoded.

Example of window Object : btoa() method

In the following web document btoa() method converts a given string to a encoded string.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript window object - btoa() method example</title>
<h1 style="color: red">JavaScript window object : btoa() method</h1>
<hr />
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
string1="Hello, world"
document.write('Before encoding the string is : '+string1 + "<br />") 
encodedData = btoa(string1)
document.write('After encoding the string is : '+encodedData + "<br />")

View the example of window object's btoa method in the browser

Supported Browser

Firefox 3.6 Google Chrome 7 Safari 5.0.1 Opera 10
Yes Yes Yes Yes

See also :

JavaScript Client side objects, methods, properties.

JavaScript Core objects, methods, properties.


Is this content useful for you?

Looking for some other tutorial?