{{APIRef("HTML DOM")}}
The WindowBase64.atob()
function decodes a string of data which has been encoded using base-64 encoding. You can use the {{domxref("WindowBase64.btoa","window.btoa()")}} method to encode and transmit data which may otherwise cause communication problems, then transmit it and use the window.atob()
method to decode the data again. For example, you can encode, transmit, and decode control characters such as ASCII values 0 through 31.
For use with Unicode or UTF-8 strings, see this note at Base64 encoding and decoding and this note at window.btoa()
.
Syntax
var decodedData = window.atob(encodedData);
Example
var encodedData = window.btoa("Hello, world"); // encode a string var decodedData = window.atob(encodedData); // decode the string
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', '#dom-windowbase64-atob', 'WindowBase64.atob()')}} | {{Spec2('HTML WHATWG')}} | No change since the latest snapshot, {{SpecName("HTML5.1")}}. |
{{SpecName('HTML5.1', '#dom-windowbase64-atob', 'WindowBase64.atob()')}} | {{Spec2('HTML5.1')}} | Snapshot of {{SpecName("HTML WHATWG")}}. No change. |
{{SpecName("HTML5 W3C", "#dom-windowbase64-atob", "WindowBase64.atob()")}} | {{Spec2('HTML5 W3C')}} | Snapshot of {{SpecName("HTML WHATWG")}}. Creation of WindowBase64 (properties were on the target before it). |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatGeckoDesktop(1)}}[1][2] | 10 | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatGeckoMobile(1)}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatVersionUnknown}} |
[1] atob()
is also available to XPCOM components implemented in JavaScript, even though window
is not the global object in components.
[2] Starting with Firefox 27, this atob()
method ignores all space characters in the argument to comply with the latest HTML5 spec. ({{ bug(711180) }})
See also
- Base64 encoding and decoding
data
URIs- {{domxref("WindowBase64.btoa","window.btoa()")}}
- Components.utils.importGlobalProperties