我正在尝试根据 this post 将 json 转换为 csv .除 IE10 外,在 Chrome 和 Firefox 中一切正常。 Window.open
似乎在 IE10 中不起作用。
window.open( "data:text/csv;charset=utf-8," + escape(str));
str
是我的 csv 字符串
使用 url "data:text/csv;charset=utf-8,xxxxxxxxxxxx"
打开一个新的空白选项卡
其中 "xxxx"
是编码的 csv 字符串。
我也试过:
var uri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(str);
var downloadLink = document.createElement("a");
downloadLink.href = uri;
downloadLink.download = "OpHis.csv";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
在 Chrome、Firefox 中有相同的结果,但在 IE10 中没有。感谢您的帮助。
最佳答案
这解决了我在 ie10 上的问题
window.navigator.msSaveOrOpenBlob(blobObject, 'msSaveBlobOrOpenBlob_testFile.txt');
您可以在此链接上找到更多信息 http://msdn.microsoft.com/en-us/library/ie/hh779016(v=vs.85).aspx
关于javascript - window.open 在 IE10 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17812659/