Window.btoa() (Function)

Encode some data into base-64 form.

Availability:

JavaScript - 1.2
Netscape - 4.0
Property/method value type:String primitive
JavaScript syntax:Nbtoa(aBinaryString)
NmyWindow.btoa(aBinaryString)
Argument list:aBinaryStringA string of binary data to be encoded

This function will encode the string passed as an argument and return a base-64 encoded version. Base-64 encoding is used to convert binary data into a form that survives transmission across a network, so the data passed in its input argument is really binary data. It is carried in a string value because JavaScript doesn't support a special binary container. However, JavaScript strings will happily accept 8 bit values and you can therefore store binary data in them. You would normally create the string of binary data by means of the String.fromCharCode() static method.

The result is a string of binary data escaped in such a way that it will survive a serial transfer through an "old-fashioned" connection. Network drivers and serial interfacing technology makes this technique largely redundant and there can be few genuine applications for this other than to decode information from legacy systems or to interface to them somehow from a web browser. The functionality has very limited portability and will likely be deprecated at some stage in the future.

See also:String.fromCharCode(), Window.atob()