I'm writing a Google Chrome extension and I want to copy some text in clipboard in a content script. I tried selecting it and then document.execCommand('copy')
- it doesn't work. I don't want Flash, because it's not easy and elegant way to achieve that. I tried background page and <input> - it doesn't work.
Is there any working, elegant and simple way to copy text to clipboard in Chrome extension? It may also use jQuery.
Regards
To Enable Shared Clipboard In Google Chrome, Open the Google Chrome browser. Type the following text in the address bar: chrome://flags#shared-clipboard-receiver . Select Enabled from the drop down list next to the Enable receiver device to handle shared clipboard feature option.
Open the file that you want to copy items from. Select the first item that you want to copy, and press CTRL+C. Continue copying items from the same or other files until you have collected all of the items that you want. The Office Clipboard can hold up to 24 items.
Highlight the text you wish to copy. 2. Right click and select "Copy" or press on CTRL+C (Windows) / CMD+C (MAC).
How to Enable Clipboard Sharing. This hidden feature is available as a flag. To find it, open a new tab, paste chrome://flags into Chrome's Omnibox and then press the Enter key. Search for “Clipboard” in the search box.
Here's some working (Coffeescript) code that does copy / paste: https://github.com/philc/vimium/blob/master/lib/clipboard.coffee
Note that the code above runs in the background page; there was a bug a while back which broke execCommand
in content scripts, and I'm not sure if that was ever fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With