title: Export to CSV using jQuery and HTML
body: <p>I have a tabular data which I need to export to csv without using any external plugin or API. I used the <code>window.open</code> method passing the MIME types but faced issues like below:</p>
  <p><a href="https://stackoverflow.com/questions/15918173/how-to-determine-whether-microsoft-excel-or-open-office-is-installed-on-the-syst">How to determine whether Microsoft Excel or OpenOffice is installed on the system using jQuery</a></p>
  <p>The code should be independent of the fact that what is being installed on the system, i.e. OpenOffice or Microsoft Excel. I believe CSV is the format which can be expected to show in both the editors.</p>
  <h2>CODE</h2>
  <pre><code>    &lt;html&gt;
  
  &lt;head&gt;
  &lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&quot;&gt;&lt;/script&gt;  
  
  &lt;script type=&quot;text/JavaScript&quot;&gt;
  $(document).ready(function(){
      $(&quot;#btnExport&quot;).click(function(e) {
          var msg = GetMimeTypes();
          //OpenOffice
          window.open('data:application/vnd.oasis.opendocument.spreadsheet,' + $('#dvData').html());
          //MS-Excel
          window.open('data:application/vnd.ms-excel,' + $('#dvData').html());
          //CSV
          window.open('data:application/csv,charset=utf-8,' + $('#dvData').html());
          e.preventDefault();
      });
  });
  
  function GetMimeTypes () {
      var message = &quot;&quot;;
          // Internet Explorer supports the mimeTypes collection, but it is always empty
      if (navigator.mimeTypes &amp;&amp; navigator.mimeTypes.length &gt; 0) {
          var mimes = navigator.mimeTypes;
          for (var i=0; i &lt; mimes.length; i++) {
              message += &quot;&lt;b&gt;&quot; + mimes[i].type + &quot;&lt;/b&gt; : &quot; + mimes[i].description + &quot;&lt;br /&gt;&quot;;
          }
      }
      else {
          message = &quot;Your browser does not support this &quot;;
         //sorry!
      }
  
      return ( message);
  }
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id=&quot;dvData&quot;&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Column One &lt;/th&gt;
          &lt;th&gt;Column Two&lt;/th&gt;
          &lt;th&gt;Column Three&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;row1 Col1&lt;/td&gt;
          &lt;td&gt;row1 Col2&lt;/td&gt;
          &lt;td&gt;row1 Col3&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
          &lt;td&gt;row2 Col1&lt;/td&gt;
          &lt;td&gt;row2 Col2&lt;/td&gt;
          &lt;td&gt;row2 Col3&lt;/td&gt;
     &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;row3 Col1&lt;/td&gt;
          &lt;td&gt;row3 Col2&lt;/td&gt;
          &lt;td&gt;row3 Col3&lt;/td&gt;  
     &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;br/&gt;
  &lt;input type=&quot;button&quot; id=&quot;btnExport&quot; value=&quot; Export Table data into Excel &quot; /&gt;
  
  &lt;/body&gt;
  </code></pre>
  <h2>Errors</h2>
  <p><strong>CSV:</strong> Unrecognised over the browsers</p>
  <p><strong>ODS &amp; Excel:</strong>  is working but I am not able to find which one to generate when system is having an excel installed or openoffice installed?</p>
  <p><strong>IE</strong> version 8 : it is totally not working, opens in a new window and as below screenshot.</p>
  <p><img src="https://i.stack.imgur.com/Ms7KU.png" alt="enter image description here" /></p>