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

只谈情不闲聊 提交于 2019-12-13 13:05:05

问题


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?


回答1:


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();


来源:https://stackoverflow.com/questions/43641182/does-document-execcommandcopy-have-a-size-limitation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!