WindowOrWorkerGlobalScope.atob()
对经过 base-64 编码的字符串进行解码。你可以使用 window.btoa()
方法来编码一个可能在传输过程中出现问题的数据,并且在接受数据之后,使用 atob() 方法再将数据解码。例如:你可以编码、传输和解码操作各种字符,比如 0-31 的 ASCII 码值。
关于针对 Unicode 或者 UTF-8 的应用方面,请查看 this note at Base64 encoding and decoding 和 btoa()
的备注。
语法
var decodedData = scope.atob(encodedData);
异常
如果传入字符串不是有效的 base64 字符串,比如其长度不是 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). |
浏览器兼容性
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.