我有将 javascript 变量下载为文件的代码,但它在 IE8 中不起作用,我该如何在 IE8 中执行此操作?
function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
pom.setAttribute('download', filename);
document.body.appendChild(pom)
pom.click();
// Remove anchor from body
document.body.removeChild(pom)
}
最佳答案
在 IE 8 和 9 中,数据 URI 只能用于图像,不能用于导航或 Javascript 生成的文件下载。
参见 http://en.wikipedia.org/wiki/Data_URI_scheme#Disadvantages
您可以通过服务器端对文件的处理来实现下载。
关于javascript - 在 IE8 中将 javascript 数据下载到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20496630/