I volontari di MDN non hanno ancora tradotto questo articolo in Italiano. Unisciti a noi e traducilo tu stesso.
Puoi anche consultare l’articolo in English (US).

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 the length of passed-in string is not a multiple of 4.

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 Living Standard
The definition of 'WindowBase64.atob()' in that specification.
Living Standard No change since the latest snapshot, HTML 5.1.
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 compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support Yes Yes

1

271

572

10 Yes Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes ?

4

271

572

? Yes ?

1. atob() ignores all space characters in the argument to comply with the latest HTML5 spec (see bug 711180).

2. atob() now defined on WindowOrWorkerGlobalScope mixin.

See also