Text not copied to clipboard in disabled textarea
See original GitHub issueI am using clipboard.js to copy text from a disabled textarea (the text is programmatically generated and I don’t want the user to edit it before copying):
<button class="copyBtn" data-clipboard-target="#myTextArea">Copy</button>
<textarea id="myTextArea" rows="10" disabled>My text here</textarea>
With the disabled property the text is not copied to the clipboard, despite the clipboard success event indicating that it is:
var clipboard = new Clipboard('.copyBtn');
clipboard.on('success', function(e) {
console.info('Action:', e.action);
console.info('Text:', e.text);
console.info('Trigger:', e.trigger);
e.clearSelection();
});
clipboard.on('error', function(e) {
console.error('Action:', e.action);
console.error('Trigger:', e.trigger);
});
Action: copy
Text: My text here
Trigger: <button data-clipboard-target="#myTextArea" class="copyBtn">
Removing the disabled property on the textarea, clipboard functions as expected and text is copied.
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Allow Copy/Paste in a disabled input text box in Firefox browsers
Firefox does not allow clipboard manipulation through JavaScript for valid security concerns. Any suggestion? Is there a work around this?
Read more >[Solved] Text area disabled, copy text? - CSS-Tricks
Hello,. Is it possible to have a text area or similar, which users can copy code from to their clipboard? Can the text...
Read more >253870 - Can't copy text from disabled textarea or text input.
There appears to be no way to select the text in these disabled fields and copy it to the clipboard. Reproducible: Always Steps...
Read more >3 Ways to Disable Copy Text in Javascript & CSS - Code Boxx
This tutorial will walk through various ways on how to disable copy text with Javascript and CSS. Free example code download included.
Read more >How to Disable Text Selection, Copy, Cut, Paste and Right-click
It's not a difficult task to make a text unselectable. All you need to do is to disable the text selectivity for all...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Have you tried
readonlyinstead ofdisabled?solution- onCopy() { const copyText = (<HTMLInputElement>document.getElementById(‘1’)); copyText.disabled = false; copyText.select(); document.execCommand(‘Copy’); copyText.disabled = true; }