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()

语法

var decodedData = scope.atob(encodedData);

异常

如果传入字符串的长度不是4的倍数,则抛出DOMException

示例

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).

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge Full support YesFirefox Full support 1
Full support 1
Full support 27
Notes
Notes atob() ignores all space characters in the argument to comply with the latest HTML5 spec (see bug 711180).
Full support 57
Notes
Notes atob() now defined on WindowOrWorkerGlobalScope mixin.
IE Full support 10Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 4
Full support 4
Full support 27
Notes
Notes atob() ignores all space characters in the argument to comply with the latest HTML5 spec (see bug 711180).
Full support 57
Notes
Notes atob() now defined on WindowOrWorkerGlobalScope mixin.
Opera Android ? Safari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

相关链接

文档标签和贡献者

标签: 
最后编辑者: zhangchen,