Javascript/ jQuery : Exporting data in CSV not working in IE

后端 未结 6 1472
太阳男子
太阳男子 2020-12-25 13:43

I need to Export Data displayed in a Table to CSV Format. I have tried lot many things but couldn\'t get it working for IE 9 and above.

I have created a dummy fiddle

6条回答
  •  长情又很酷
    2020-12-25 14:35

    This is also one of the answers which I used and working great for IE 10+ versions :

    var csv = JSON2CSV(json_obj);            
    var blob = new Blob([csv],{type: "text/csv;charset=utf-8;"});
    
    if (navigator.msSaveBlob) { // IE 10+
    navigator.msSaveBlob(blob, "fileName.csv")
        } else {
            var link = document.createElement("a");
            if (link.download !== undefined) { // feature detection
                // Browsers that support HTML5 download attribute
                var url = URL.createObjectURL(blob);
                link.setAttribute("href", url);
                link.setAttribute("download", "fileName.csv");
                link.style = "visibility:hidden";
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
            }           
        }
    

    Hope this helps.

提交回复
热议问题