Monday, May 20, 2024
180
rated 0 times [  185] [ 5]  / answers: 1 / hits: 21513  / 10 Years ago, fri, march 28, 2014, 12:00:00

I'm having a hard time finding any recent info on how to add a listener for Ctrl+C, fetching clipboard data, and then writing back to clipboard all in a Chrome Extension. All of the old code that i found was for the older versions that are now deprecated.


More From » google-chrome

 Answers
12

Basically you can manipulate clipboard using document.execCommand('paste|copy|cut').




  • You'll need to specify clipboardWrite and/or clipboardRead permissions in manifest.




    clipboardRead Required if the extension or app uses document.execCommand('paste').



    clipboardWrite Indicates the extension or app uses document.execCommand('copy') or document.execCommand('cut'). This permission is required for hosted apps; it's recommended for extensions and packaged apps.



  • Create <input> element (or <textarea>)


  • Put focus to it

  • Call document.execCommand('paste')

  • Grab you string from <input> value attribute.



This worked for me to copy data to clipboard.


[#71740] Wednesday, March 26, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lailab

Total Points: 706
Total Questions: 102
Total Answers: 95

Location: Falkland Islands
Member since Mon, Jul 13, 2020
4 Years ago
;