W3cubDocs

/DOM

WindowOrWorkerGlobalScope.atob

The WindowOrWorkerGlobalScope.atob() function decodes a string of data which has been encoded using base-64 encoding. You can use the btoa() method to encode and transmit data which may otherwise cause communication problems, then transmit it and use the 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 btoa().

Syntax

var decodedData = scope.atob(encodedData);

Throws

Throws a DOMException if encodedData is not valid base64.

Example

var encodedData = window.btoa('Hello, world'); // encode a string
var decodedData = window.atob(encodedData); // decode the string

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'WindowOrWorkerGlobalScope.atob()' in that specification.
Living Standard Method moved to the WindowOrWorkerGlobalScope mixin in the latest spec.
HTML 5.1
The definition of 'WindowBase64.atob()' in that specification.
Recommendation Snapshot of HTML Living Standard. No change.
HTML5
The definition of 'WindowBase64.atob()' in that specification.
Recommendation Snapshot of HTML Living Standard. Creation of WindowBase64 (properties were on the target before it).

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support Yes Yes 1
1
27
atob() ignores all space characters in the argument to comply with the latest HTML5 spec (see bug 711180).
57
atob() now defined on WindowOrWorkerGlobalScope mixin.
10 Yes Yes
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes ? 4
4
27
atob() ignores all space characters in the argument to comply with the latest HTML5 spec (see bug 711180).
57
atob() now defined on WindowOrWorkerGlobalScope mixin.
? Yes ?

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/atob