javascript - 在 IE8 中将 javascript 数据下载到文件

标签 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('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/

相关文章:

javascript - 在IE7和IE6中,设置element.style ['display' ] = 'inherit'会抛出异常

html - 着色 CSS 半圆

javascript - 搜索引擎优化和显示 : none

internet-explorer - Asp.net Core 缓存 + IE 11 导致缓存响应

c# - 以编程方式更改 Internet Explorer 设置?

javascript - jQuery show/hide options if first one selected, 默认显示第二个选择的选项

javascript - Vue.js:Nuxt 错误处理

javascript - Firefox - 如何在使用双击时获取选定的文本

javascript - 匹配每 4 个元素的高度

internet-explorer - 当系统有许多具有相同 "Major Version"的版本时,如何检查特定版本的 flash player 的存在(在 javascript 中)?