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),可以使用Buffer
s进行解码.
For server-side JavaScript (Node), you can use Buffer
s 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 编码和解码


- 失败的 Canvas 360 jquery 插件 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01