-2

I'm looking for a solution to download a csv file in safari, I have in the link data:text/csv;charset=UTF-8 ....etc what's happen is in safari it open a plain textcsv in the browser NB: everything is ok on chrome and IE

Do you have any Ideas.. Thank you

tgogos
  • 23,218
  • 20
  • 96
  • 128
imtah
  • 409
  • 1
  • 6
  • 16

1 Answers1

0

I found this: Javascript - Download CSV as File and changed it a little bit to make it work with jQuery.

$(document).ready(function(){

  function downloadFile2(fileName, urlData){
      $('#dlink').attr('download',fileName);
      $('#dlink').attr('href',urlData);
      $('#dlink')[0].click();
  }

  var data = '"Column One","Column Two","Column Three"';
  downloadFile2('2.csv','data:text/csv;charset=UTF-8,' + encodeURIComponent(data));

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<a id="dlink" href="" style="display:none"></a>
Community
  • 1
  • 1
tgogos
  • 23,218
  • 20
  • 96
  • 128