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 编码和解码


基础教程推荐
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 直接将值设置为滑块 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01