Created
April 30, 2017 10:49
-
-
Save roden0/3d593eb80c7b347a375e6e568ec30c20 to your computer and use it in GitHub Desktop.
Revisions
-
roden0 created this gist
Apr 30, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ <a download="somedata.csv"href="data:application/csv;charset=utf-8,Col1%2CCol2%2CCol3%0AVal1%2CVal2%2CVal3%0AVal11%2CVal22%2CVal33%0AVal111%2CVal222%2CVal333">Example</a> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ var data =[["name1","city1","some other info"],["name2","city2","more info"]]; var csvContent ="data:text/csv;charset=utf-8,"; data.forEach(function(infoArray, index){ dataString = infoArray.join(","); csvContent += index < infoArray.length ? dataString+"\n": dataString; }); var encodedUri = encodeURI(csvContent); window.open(encodedUri); var encodedUri = encodeURI(csvContent);var link = document.createElement("a"); link.setAttribute("href", encodedUri); link.setAttribute("download","my_data.csv"); link.click();// This will download the data file named "my_data.csv".