document.execCommand('copy') 有大小限制吗? [英] Does document.execCommand('copy') have a size limitation?

查看:49
本文介绍了document.execCommand('copy') 有大小限制吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的 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

就我而言,我将 Kendo 网格中的数据放入要复制的隐藏文本区域.在 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.

我已取消隐藏 textarea 以确保它获取网格的完整内容,并且这是有效的.我可以从可见文本区域手动复制所有 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.

尝试取消隐藏 textarea 并查看您的代码是否有效.

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆