Skip to content

Instantly share code, notes, and snippets.

@pradeepn
Created February 6, 2015 06:57
Show Gist options
  • Save pradeepn/264b953ca15777fb64b4 to your computer and use it in GitHub Desktop.
Save pradeepn/264b953ca15777fb64b4 to your computer and use it in GitHub Desktop.
Client File Download
//$.borwser plugin
//$.fileDownload plugin
downloadCsv: function (filename, array, dilem) {
var csvString = _JSONtoCSV(array, dilem);
console.log(csvString);
if ($.browser.msie == true) {//HTML5 Download attribute not available in ie
$.fileDownload('/downloadcsv', { httpMethod: "POST", data: { CsvString: csvString, FileName: filename} });
}
else {
var a = document.createElement('a');
a.href = 'data:attachment/csv,' + escape(csvString);
a.target = '_blank';
a.download = filename;
a.style = "visibility:hidden";
document.body.appendChild(a);
a.click();
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment