问题描述
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 编码和解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)