【发布时间】:2017-10-18 20:34:08
【问题描述】:
我有一个网页,其中有一个按钮,单击该按钮会生成一个(通过从 json 进行转换)由浏览器下载的 csv 文件。它本质上使用了来自jsfiddle 的逻辑。这一切都适用于 chrome,但在 IE 中,没有任何反应。
var uri = 'data:text/csv;charset=utf-8,' + escape(CSV);
// Now the little tricky part.
// you can use either>> window.open(uri);
// but this will not work in some browsers
// or you will not get the correct file extension
//this trick will generate a temp <a /> tag
var link = document.createElement("a");
link.href = uri;
//set the visibility hidden so it will not effect on your web-layout
link.style = "visibility:hidden";
link.download = fileName + ".csv";
//this part will append the anchor tag and remove it after automatic click
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
问题似乎是 Internet Explorer 中不存在锚标记的下载属性。我一直在查看大量文章和 SO 帖子,但我还没有找到可以在页面中使用的连贯解决方案。
jsfiddle中的代码如何在IE中实现?
【问题讨论】:
-
列出您正在测试的 IE 版本以及异常情况可能会有所帮助。
-
对不起,实际上我后来尝试的东西返回了运行时异常。我最初使用的代码(类似于 jsfiddle)在单击按钮时什么也没做,但是在 chrome 中,文件下载并且您可以选择打开它。这是在 IE 11 中。
标签: javascript jquery html csv internet-explorer