如何下载JavaScript字符串并将其保存到字符集“ gbk”编码的文件中

时间:2019-06-03 12:16:19

标签: javascript

//Now I define a Chinese string:'您好', and I want to download it and save to a file
var str="data:text/csv;charset=gbk" + encodeURI('您好');
//set a link for download
var link = document.createElement("a");
link.setAttribute("href", str);
link.setAttribute("download", ''filename''); 
document.body.appendChild(link);
//click to download 
link.click();

如果我下载并将其保存到文件中,它将由utf8编码,但我想通过gbk对其进行编码。

谢谢!

0 个答案:

没有答案