我有一个网页,其中有一个按钮,单击它时会生成(通过从json进行转换)csv文件,该文件由浏览器下载。它基本上使用了这个jsfiddle的逻辑。这一切都适用于Chrome,但在IE中,没有任何反应。如何使用JS(Internet Explorer)以编程方式下载文件
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帖子,但我还没有找到一个可以在页面中使用的连贯解决方案。
如何在IE中实现jsfiddle的代码?
这可能有助于列出您正在测试的IE版本以及异常情况。 – Marquis
对不起,实际上我以后试过的东西返回了一个运行时异常。我最初使用的代码(类似于jsfiddle)在单击按钮时没有做任何事情,但在Chrome中,文件下载并且您可以选择打开它。这是在IE 11中。 – loremIpsum1771