We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

概述

WindowOrWorkerGlobalScope.atob() 对用base-64编码过的字符串进行解码 。你可以使用 window.btoa() 方法来编码一个可能在传输过程中出现问题的数据,并且在接受数据之后,使用 atob() 方法再将数据解码。例如:你可以编码、传输和解码操作各种字符,比如0-31的ASCII码值。

关于针对Unicode或者UTF-8的应用方面,请查看 this note at Base64 encoding and decoding  和 this note at window.btoa()

语法

let decodedData = window.atob(encodedData);

例子

let encodedData = window.btoa("Hello, world"); // 编码
let decodedData = window.atob(encodedData); // 解码

规范                                                

Specification Status Comment
HTML Living Standard
WindowBase64.atob()
Living Standard No change since the latest snapshot, HTML 5.1.
HTML 5.1
WindowBase64.atob()
Recommendation Snapshot of HTML Living Standard. No change.
HTML5
WindowBase64.atob()
Recommendation Snapshot of HTML Living Standard. Creation of WindowBase64 (properties were on the target before it).

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) 1.0 (1.7 or earlier)[1]
27 (27)[2]
10 (Yes) (Yes)
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) 1.0 (1) 未实现 ? (Yes)

[1] atob() 也适用于用JavaScript实现的XPCOM组件,尽管在组件里面 window 不再是全局对象。

[2] 从 Firefox 27 开始, 遵从最新的HTML5 spec,atob() 会忽略所有的空白字符。 (bug 711180)

相关链接

 

 

文档标签和贡献者

标签: 
最后编辑者: nkliyc,