title: Download CSV URL as .csv file using Javascript (HTML content formatted as CSV)
body: <p>How can I download an html page where my content is already formatted as csv.</p>
  
  <p>I keep finding how to export JSON to csv, or data table to csv, but nothing on how to actually download a html content formatted as csv to an actual .csv file on page load.</p>
  
  <p>Thanks in advance for your help.</p>
  
  <p>see my code below</p>
  
  <pre><code>    &lt;script type="text/javascript" src="http://example.com/Pulling-JSON-Data.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  
      $('html').append(
          "Category 1, Category 2, Category 3" +
          "&lt;br/&gt;"
      );
  
      $(dataName).each(function(index) {
              $('html').append(
                  "&amp;quot;" + this.exemple1 + "&amp;quot;," + 
                  "&amp;quot;" + this.exemple2 + "&amp;quot;," + 
                  "&amp;quot;" + this.exemple3 + "&amp;quot;," +          
                  "&lt;br /&gt;"
              );
          });
  
  
      var CSVdata = document.createElement('a');
      CSVdata.href = "data:application/csv;charset=utf-8," + encodeURI(dataName);
      CSVdata.target = '_blank';
      CSVdata.download = 'file.csv';
      CSVdata.click();
  
  &lt;/script&gt;
  </code></pre>