Base64 encoding and decoding in client-side Javascript(客户端 Javascript 中的 Base64 编码和解码)
问题描述
JavaScript 中是否有任何方法可用于使用 base64 编码对字符串进行编码和解码?
Are there any methods in JavaScript that could be used to encode and decode a string using base64 encoding?
推荐答案
一些浏览器,如 Firefox、Chrome、Safari、Opera 和 IE10+ 可以原生处理 Base64.看看这个 Stackoverflow 问题.它使用 btoa() 和 atob() 函数.
Some browsers such as Firefox, Chrome, Safari, Opera and IE10+ can handle Base64 natively. Take a look at this Stackoverflow question. It's using btoa() and atob() functions.
对于服务器端的JavaScript(Node),可以使用Buffers进行解码.
For server-side JavaScript (Node), you can use Buffers to decode.
如果您要使用跨浏览器解决方案,可以使用现有的库,例如 CryptoJS 或类似代码:
If you are going for a cross-browser solution, there are existing libraries like CryptoJS or code like:
http://ntt.cc/2008/01/19/base64-encoder-decoder-with-javascript.html(存档)
对于后者,您需要彻底测试该功能的跨浏览器兼容性.并且错误已被报告.
With the latter, you need to thoroughly test the function for cross browser compatibility. And error has already been reported.
这篇关于客户端 Javascript 中的 Base64 编码和解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:客户端 Javascript 中的 Base64 编码和解码
基础教程推荐
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
