WindowOrWorkerGlobalScope.atob() - Web APIs 编辑

The WindowOrWorkerGlobalScope.atob() function decodes a string of data which has been encoded using Base64 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 the note on "Unicode strings" in the page for btoa().

Syntax

var decodedData = scope.atob(encodedData);

Parameters

encodedData
A binary string contains an base64 encoded data.

Return value

An ASCII string containing decoded data from encodedData.

Exceptions

DOMException (name: InvalidCharacterError)
Throws if encodedData is not valid base64.

Example

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

Polyfill

You can use a polifill from https://github.com/MaxArt2501/base64-js/blob/master/base64.js for browsers that don't support it.

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of 'WindowOrWorkerGlobalScope.atob()' in that specification.
Living StandardMethod moved to the WindowOrWorkerGlobalScope mixin in the latest spec.
HTML 5.1
The definition of 'WindowBase64.atob()' in that specification.
RecommendationSnapshot of HTML Living Standard. No change.
HTML5
The definition of 'WindowBase64.atob()' in that specification.
RecommendationSnapshot of HTML Living Standard. Creation of WindowBase64 (properties where on the target before it).

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:136 次

字数:4611

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文