2

I would like to export a WebSQL database into a csv file locally on a mobile device using a webkit browser. Currently this code works inside google chrome and creates a file that automatically downloads:

testCSV = function(){
 var csvData = "";
 db.transaction(function(tx){
 tx.executeSql('SELECT * FROM grocery', [], function (tx, results){
 var len = results.rows.length, i;

  for (i = 1; i < len; i++) {
   csvData += results.rows.item(i).itemno + "," + results.rows.item(i).quantity + "\n";
   }
 window.location='data:text/csv;charset=utf8,' + encodeURIComponent(csvData);
  });

 });
};

When I run the same code on the mobile device it opens and displays the csv text in the browser. How can I get it to download the file and save it locally. Any ideas?

Tim
  • 785
  • 1
  • 7
  • 20
  • one thing we've done is to generate an html table from the websql users can then use their browsers copy and paste feature to paste the table into an office application on the device or an e-mail to send to a desktop computer. – ajayel Feb 22 '12 at 05:34

1 Answers1

0

Change text/csv to a custom MIME type such as application/webcsv to trigger the download prompt for an unknown file type.

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265