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

在使用浏览器内置API btoa() 编码base64时:
报错Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range

报错信息解释:
报错信息中指出字符串中包含了Latin1范围之外的字符,导致无法使用window.btoa进行解析。根据你提供的字符串,我们可以看到其中包含了中文字符"区"和"桥",这些字符属于Unicode字符集,超出了Latin1范围。

为了解决这个问题,你可以使用其他方法或库来进行编码。比如js-base64即可

推荐阅读:
维基百科-Latin1:https://zh.wikipedia.org/wiki/ISO/IEC_8859-1
维基百科-Unicode:https://zh.wikipedia.org/wiki/Unicode
MDN-bota:https://developer.mozilla.org/zh-CN/docs/Web/API/btoa

posted @ 2023-08-21 12:02  w1ndz  阅读(4448)  评论(0)    收藏  举报