Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does document.execCommand('copy') have a size limitation?

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?

like image 309
Grid Trekkor Avatar asked Apr 26 '17 17:04

Grid Trekkor


1 Answers

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();
like image 87
Slow_5_0 Avatar answered Sep 23 '22 11:09

Slow_5_0