如何在 gm_xmlhttprequest 中正确处理 euc-jp 编码以显示日文
在使用 gm_xmlhttprequest 请求编码为 euc-jp 的网站时,若使用 encoding.min.js 转码后结果仍然乱码,原因可能是转码方式不正确。本文将探讨如何正确处理 euc-jp 编码以正常显示日文文字。
解决方案:
使用原生 javascript 的 textdecoder api 进行解码,代码如下:
const ab2str = (arrayBuf, encodeType) => { var decoder = new TextDecoder(encodeType); var u8arr = new Uint8Array(arrayBuf); return decoder.decode(u8arr); }; ab2str(response.response, 'EUC-JP');
这段代码将 arraybuffer 转换为 euc-jp 编码的字符串。
参考:
以上就是GM_xmlhttpRequest请求EUC-JP编码的网站数据乱码怎么办?的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号