document.execCommand('copy')是否有大小限制? [英] Does document.execCommand('copy') have a size limitation?
问题描述
我正在使用类似于此处所述的document.execCommand('copy'):
I am using document.execCommand('copy') similar to what is described here:
https://developers.google.com/web/updates/2015/04/cut-and-copy-commands
就我而言,我是将剑道网格中的数据放置到要复制的隐藏文本区域中.复制在2500至3000行之间,或大约350k的数据中,失败.
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.
我已取消隐藏文本区域,以确保其获取网格的全部内容,并且该方法有效.我可以从可见的文本区域手动复制所有3000多个行.
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.
但是document.execCommand无法复制它.我要达到一些尺寸限制吗?
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.
我遇到了一个隐藏的texarea类似的东西.我最终做了这样的事情.
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();
这篇关于document.execCommand('copy')是否有大小限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!