将javascript数据下载到IE8中的文件中

将javascript数据下载到IE8中的文件中,javascript,html,internet-explorer,Javascript,Html,Internet Explorer,我有代码可以下载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('downlo

我有代码可以下载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)
}

在IE8和IE9中,数据URI只能用于图像,不能用于导航或Javascript生成的文件下载


您可以通过服务器端处理文件来实现下载。

您可以将数据发送到服务器端脚本,该脚本将以正确的下载头进行响应。