码上敲享录 > js常见问题解答 > execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range

execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range

上一章章节目录下一章 2022-08-13已有2338人阅读 评论(0)

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


解决方法:

使用window.btoa加密失败,报错如下:

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

原因是加密的的字符串中有特殊字符那些,所以得先使用window.encodeURIComponent编码再加密。

var str64 = window.btoa(window.encodeURIComponent(str))


0

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交