大地瓜的博客

Home Archives
2018-04-02

Javascript 中 atob 方法解码中文字符乱码

Uncaught DOMException: Failed to execute ‘btoa’ on ‘Window’: The string to be encoded contains characters outside of the Latin1 range.

1.借助 encodeURIComponent 和 decodeURIComponent 转义非中文字符

编码

> window.btoa(encodeURIComponent('中文'))
"JUU0JUI4JUFEJUU2JTk2JTg3"
解码

> decodeURIComponent(window.atob('JUU0JUI4JUFEJUU2JTk2JTg3'))
"中文"

2.第三方 Base64 工具

https://gitee.com/loonhxl/jbase64/blob/master/jbase64.js

Share
Newer
h5 history nginx配置
Older
linux

标签

  • 3D
  • LeetCode
  • html
  • javascript
  • webgl
  • 算法
  • 算法, LeetCode

标签云

3D LeetCode html javascript webgl 算法 算法, LeetCode

归档

  • 四月 2022
  • 一月 2022
  • 二月 2021
  • 一月 2021
  • 十二月 2020
  • 六月 2019
  • 四月 2019
  • 三月 2019
  • 十二月 2018
  • 十一月 2018
  • 十月 2018
  • 九月 2018
  • 八月 2018
  • 七月 2018
  • 六月 2018
  • 五月 2018
  • 四月 2018
  • 三月 2018
  • 二月 2018
  • 一月 2018
  • 十二月 2017
  • 九月 2017
  • 八月 2017
  • 六月 2017
  • 五月 2017
  • 四月 2017
  • 三月 2017
  • 二月 2017
  • 一月 2017
  • 十二月 2016
  • 十一月 2016
  • 十月 2016
  • 九月 2016
  • 八月 2016
  • 七月 2016
  • 六月 2016
  • 五月 2016
  • 四月 2016
  • 三月 2016
  • 二月 2016
  • 一月 2016
  • 十二月 2015

最新文章

  • Hello World
  • 编译自己的chrome(一)
  • SameSite
  • ts复习
  • 用rust写前端(一)
© 2022 John Doe
Powered by Hexo
Home Archives