title: Copying custom json object to clipboard with javascript
body: <p>I'm developing a shared canvas using HTML5 + javascript. I am developing copying/pasting functionality, and I have no problems to do it with Ctrl+C, +X, +V, but I also would like to add the typical buttons that provide the same functionality (mainly intended to be able to copy/paste in tablets).</p>
  
  <p>The code to manage the standard events is quite straigtforward:</p>
  
  <pre><code>window.addEventListener("copy", copyFunc);
  
  ...
  
  copyFunc(e){
    if (BDKanvasInstance.selection !== null){
      var data = BDKanvasInstance.selection.serialize();
      var jsonData = JSON.stringify(data);
      e.clipboardData.setData('application/json', jsonData);
      e.preventDefault();
    }
  }
  </code></pre>
  
  <p>But I have to way to access the clipboardData from a button... </p>
  
  <pre><code>copyBtn.addEventListener("click", copyBtnFunc);
  
  copyBtnFunc(e){
    /* Any way to access clipboardData or to trigger the standard copy command? */
  }
  </code></pre>
  
  <p>I've seen several solutions involving creating a textarea, inserting the text, selecting it programmatically and using "execCommand('copy')", but that does not copy the text with an "application/json" type...</p>
  
  <p>Any solutions? With a computer using keyboard shortcuts is ok, but they are not a solution when using it on the tablet...</p>
  
  <p>Thank you!</p>