I am using document.execCommand('copy') similar to what is described here:
https://developers.google.com/web/updates/2015/04/cut-and-copy-commands
In my case, I'm placing data from a Kendo grid into a hidden textarea to be copied. Somewhere between 2500 and 3000 rows, or around 350k of data, the copy fails.
I've unhidden the textarea to make sure it's getting the full contents of the grid, and that is working. I can copy all 3000+ rows manually from the visible textarea.
But document.execCommand fails to copy it. Is there some size limitation I'm reaching?
When you say "fails to copy" I am assuming you are not getting an error but it's just not adding anything to the clipboard.
Try unhidding the textarea and see if your code works.
I ran into something similar with a hidden texarea. I ended up doing something like this.
$('#txtCopy').show();
var copyData = document.querySelector('#txtCopy');
window.getSelection().removeAllRanges();
var range = document.createRange();
range.selectNodeContents(copyData);
window.getSelection().addRange(range);
var successful = document.execCommand('copy');
console.log(successful);
$('#txtCopy').hide();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With