问题描述
我想将文本区域中的文本内容下载为ANSI编码的文本文件,而不是UTF-8。
作为here中的答案,我将能够下载文本文件。但是问题是使用UTF-8编码
我通过更改类型尝试如下,但没有用
function saveTextAsFile(textToWrite,fileNameToSaveAs) {
var textFileAsBlob = new Blob([textToWrite],{
type: 'text/plain;charset=ANSI'
});
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
if (window.webkitURL != null) {
// Chrome allows the link to be clicked
// without actually adding it to the DOM.
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
} else {
// Firefox requires the link to be added to the DOM
// before it can be clicked.
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
downloadLink.click();
}
有什么方法可以做到吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)