1

I am generating a table of clicks' coordinates here. Try clicking somewhere on the field, you'll understand.

Now, I want to export this table as CSV file. I need to make it work with iPad or Tablet.

Hopefully you guys can help me!

Yeldar Kurmangaliyev
  • 30,498
  • 11
  • 53
  • 87
  • Hopefully, you know that you have tens of errors in your console (there is no element with id `status`). – Yeldar Kurmangaliyev Dec 02 '15 at 10:51
  • 1
    [This](http://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side) may be of use to you. – Saad Dec 02 '15 at 10:53

1 Answers1

0

You need to do the following:

  1. Convert your table contents to CSV text:

    var rows = document.querySelectorAll('#table tr');
    var csvText = [].map.call(rows, function(row) {
        return [].map.call(row.children, function(cell) { return cell.innerText; }).join(';');
    }).join('\n');
    
  2. Create a Blob from this CSV

    var blob = new Blob([csvText], { type: 'text/csv' });
    
  3. Download this Blob:

    var a = document.createElement('a');
    a.download = 'export.csv';
    a.href = URL.createObjectURL(blob);
    a.click();
    

Blob constructing is supported by all modern browsers, but you may want to check this compatibility table.

Yeldar Kurmangaliyev
  • 30,498
  • 11
  • 53
  • 87