Jquery 从IE11下的javascript生成CSV文件
我阅读了很多示例,从数据生成csv文件,并将其推送到下载以导出Jquery 从IE11下的javascript生成CSV文件,jquery,export-to-csv,Jquery,Export To Csv,我阅读了很多示例,从数据生成csv文件,并将其推送到下载以导出 let csvContent = ''; $.each(msg.d.LstObj[0], function (key, element) { csvContent += (csvContent === '' ? '' : ',') + key; }); csvContent += "\n"; msg.d.LstObj.forEach(f
let csvContent = '';
$.each(msg.d.LstObj[0], function (key, element) { csvContent += (csvContent === '' ? '' : ',') + key; });
csvContent += "\n";
msg.d.LstObj.forEach(function (rowArray) {
var row = '';
$.each(rowArray, function (key, element) { row += (row === '' ? '' : ',') + element; });
csvContent += row + "\n";
});
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csvContent);
hiddenElement.target = '_blank';
hiddenElement.download = 'people.csv';
hiddenElement.click();
在chromeff下:好的
在IE11下:不下载只是一条信息问我:
voulez vous autoriser ce站点webáouvrir une应用程序
只有一家精选的windows商店。。。
有人有主意吗???我把我的代码放在“网站公开” 这是我用来满足所有浏览器(包括IE 11)的块,它对我来说非常有用:
if (window.navigator.msSaveBlob) {
//Internet Explorer
window.navigator.msSaveBlob(new Blob([result]), csvFileName);
} else if (window.webkitURL != null) {
//Google Chrome and Mozilla Firefox
var a = document.createElement("a");
result = encodeURIComponent(result);
a.href = "data:application/csv;charset=UTF-8," + result;
a.download = csvFileName;
a.click();
} else if (navigator.appName === "Microsoft Internet Explorer") {
//Internet Explorer 8 and 9
var oWin = window.open();
oWin.document.write("sep=,\r\n" + result);
oWin.document.close();
oWin.document.execCommand("SaveAs", true, csvFileName);
oWin.close();
} else {
//Everything Else
window.open(result);
}
下面是我用来满足所有浏览器(包括IE 11)的块,它对我非常有用:
if (window.navigator.msSaveBlob) {
//Internet Explorer
window.navigator.msSaveBlob(new Blob([result]), csvFileName);
} else if (window.webkitURL != null) {
//Google Chrome and Mozilla Firefox
var a = document.createElement("a");
result = encodeURIComponent(result);
a.href = "data:application/csv;charset=UTF-8," + result;
a.download = csvFileName;
a.click();
} else if (navigator.appName === "Microsoft Internet Explorer") {
//Internet Explorer 8 and 9
var oWin = window.open();
oWin.document.write("sep=,\r\n" + result);
oWin.document.close();
oWin.document.execCommand("SaveAs", true, csvFileName);
oWin.close();
} else {
//Everything Else
window.open(result);
}
只需对[open excel in UTF-8]()稍加修改即可(只需对[open excel in UTF-8]()稍加修改即可)