Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

window.atob

概述

WindowBase64.atob() 函数用来解码一个已经被base-64编码过的数据。你可以使用 window.btoa() 方法来编码一个可能在传输过程中出现问题的数据,并且在接受数据之后,使用 window.atob() 方法来将数据解码。例如:你可以把ASCII里面数值0到31的控制字符进行编码,传输和解码。关于针对Unicode或者UTF-8的应用方面,请查看 this note at Base64 encoding and decoding  和 this note at window.btoa()

语法

var decodedData = window.atob(encodedData);

例子

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

规范                                                

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

浏览器兼容性

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)

相关链接

 

 

文档标签和贡献者

 此页面的贡献者: ziyunfei, happyWang, teoli, khalid32
 最后编辑者: happyWang,