Abhishek Kumar

Abhishek Kumar

  • NA
  • 558
  • 111.8k

Why firefox does not create a file as csv it creates as part

Oct 30 2015 6:39 AM
Hi,
When i export html table to csv firefox is not creating as csv its creating as .csv.part.
This is my code:-
 
function exportTable($table, filename) {
var $rows = $table.find('tr:has(td)'),
tmpColDelim = String.fromCharCode(11), 
tmpRowDelim = String.fromCharCode(0), 
colDelim = ",",
rowDelim = "\r\n",
csv = $rows.map(function (i, row) {
var $row = $(row),
$cols = $row.find('td');
return $cols.map(function (j, col) {
var $col = $(col),
text = $col.text();
return text.replace(/"/g, '""');
}).get().join(tmpColDelim);
}).get().join(tmpRowDelim)
.split(tmpRowDelim).join(rowDelim)
.split(tmpColDelim).join(colDelim) ,
// Data URI
csvData = 'data:application/text;charset=utf-8,' + encodeURIComponent(csv);
$(this)
.attr({
'download': filename,
'href': csvData,
'target': '_blank'
});
}
 
I also used data:application/csv but it does not work.
 
But this code effectively works in Chrome..
Please help!!!
Thanks in advance... 
 
 

Answers (2)