मैं कुछ टेक्स्ट डालने के लिए एक छिपे हुए टेक्स्ट क्षेत्र का उपयोग कर रहा हूं, इसे चुनें और उसके बाद document.execCommand का उपयोग क्लिपबोर्ड पर कॉपी करने के लिए कर रहा हूं। यह आमतौर पर काम करता है लेकिन टेक्स्ट बड़ा होने पर विफल रहता है (झूठा रिटर्न)। क्रोम v55 में, ऐसा लगता है कि यह लगभग 180 के वर्णों में विफल रहता है।document.execCommand ('copy') के साथ क्लिपबोर्ड पर कॉपी करना बड़े ग्रंथों के साथ विफल रहता है
क्या इस डेटा की प्रतिलिपि बनाई जा सकने वाली डेटा की सीमा है? सामान्य Ctrl + C समान सीमाओं के अधीन प्रतीत नहीं होता है।
नोट: किसी ने इसे Does document.execCommand('copy') have a size limitation? के संभावित डुप्लिकेट के रूप में चिह्नित किया है। यह एक समान सवाल हो सकता है, लेकिन उस व्यक्ति को एक विशिष्ट ढांचे के रूप में टैग किया गया था जिसका मैं उपयोग नहीं करता हूं और इसका उत्तर भी नहीं दिया गया था। मेरा मानना है कि मेरा प्रश्न अधिक सामान्य और अभी भी प्रासंगिक है।
मैं संदर्भ के लिए कोड संलग्न करता हूं।
function copyTextToClipboard(text) {
var textArea = document.createElement('textarea');
textArea.style.position = 'fixed';
textArea.style.top = 0;
textArea.style.left = 0;
textArea.style.width = '2em';
textArea.style.height = '2em';
textArea.style.padding = 0;
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';
textArea.style.background = 'transparent';
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
document.body.removeChild(textArea);
}
संभावित डुप्लिकेट https://stackoverflow.com/questions/43641182/does-document-execcommandcopy- एक-आकार-सीमा है) –
संपादित देखें। वह सवाल हल नहीं किया गया था। –