title: How to add a meta tag to clipboard when copying programmatically with javascript?
body: <p>I am trying to programmatically insert a table into clipboard to be pasted into google spreadsheets.</p>
  
  <p>Here is what I have done:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$('.copy').click(function() {
   var copyContainer = $('&lt;div&gt;'); //a hidden container to copy from
   copyContainer.append('&lt;meta name="generator" content="Sheets"/&gt;');
    
   copyContainer.css('position', 'absolute').css('z-index', -999).css('opacity', 0);
   $('body').prepend(copyContainer);
   copyContainer.attr('contenteditable', true);
   
      // Let's grab a table from html to make example simpler
   copyContainer.append($('table').clone());
   copyContainer.select();
    
   copyContainer.on('focus', function() { 
    document.execCommand('selectAll',false,null) 
   });
   copyContainer.focus();
    
   document.execCommand('copy');
   copyContainer.remove();
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;button class="copy"&gt;Copy!&lt;/button&gt;
  &lt;table&gt;&lt;tr&gt;&lt;td data-sheets-note="test"&gt;123&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The problem is that this puts the following into my clipboard:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;!--StartFragment--&gt;
    &lt;table style="color: rgb(0, 0, 0); font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td data-sheets-note="test"&gt;123&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
     &lt;/table&gt;
  &lt;!--EndFragment--&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But this (the same with an added meta tag) is what I need (so the google spreadsheets would recognize it correctly and add the note to the cell):</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;!--StartFragment--&gt;
    &lt;meta name="generator" content="Sheets"/&gt;
    &lt;table style="color: rgb(0, 0, 0); font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td data-sheets-note="test"&gt;123&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
     &lt;/table&gt;
  &lt;!--EndFragment--&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>How coudl I force the meta tag to be added in the clipboard?</p>