title: Saving CSV file using blob in Safari
body: <p>I have codes below to generate the download link so that users could download the  .csv file on my site.</p>
  
  <pre><code>var link = document.createElement("a");
  link.id = "csvDwnLink";
  window.URL = window.URL || window.webkitURL;
  
  var csv = "\ufeff" + CSV,
      blob = new window.Blob([csv], {type: 'text/csv, charset=UTF-8'}),
      csvUrl = window.URL.createObjectURL(blob),
      filename = 'export.csv';
  
  $("#csvDwnLink").attr({'download': filename, 'href': csvUrl});
  $('#csvDwnLink')[0].click();
  document.body.removeChild(link);
  </code></pre>
  
  <p>I hope the user could click the download link with <code>csvUrl</code> to download the cvs file.<br>
  It works on chrome. However, when I click the same link using Safari, it will directly show me the content of the csv file in the tab. </p>
  
  <p>How do I solve this problem so that the safari will show the saving file window which user could select the path where they want to save the file instead of showing the content of the cvs file directly when I click the download link?<br>
  Hope someone could me some recommendations or alternative methods.<br>
  Thanks in advance!</p>
  
  <p><strong>== Updated ==</strong><br>
  Find out solutions here<br>
  <a href="https://adilapapaya.wordpress.com/2013/11/15/exporting-data-from-a-web-browser-to-a-csv-file-using-javascript/" rel="nofollow noreferrer">solution 1</a>, 
  <a href="https://stackoverflow.com/questions/16078544/export-to-csv-using-jquery-and-html">solution 2</a></p>
  
  <p>The code will be:</p>
  
  <pre><code>var link = document.createElement("a");
  link.id = "csvDwnLink";
  
  document.body.appendChild(link);
  window.URL = window.URL || window.webkitURL;
  var csv = "\ufeff" + CSV,
      csvData = 'data:attachment/csv;charset=utf-8,' + encodeURIComponent(csv),
      filename = 'filename.csv';
  $("#csvDwnLink").attr({'download': filename, 'href': csvData});
  $('#csvDwnLink')[0].click();
  document.body.removeChild(link);
  </code></pre>
  
  <p>Safari will download the file for the user, however, the file name will be <code>unknown</code>, probably it's because Safari don't support 'download' attribute yet as <code>raphael</code> mentioned.</p>