10 lines to copy any text to the clipboard
Trishul Goel
trishul.goel at gmail.com
Fri Aug 4 09:49:09 UTC 2017
Hi Damien,
Refer following
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Interact_with_the_clipboard
May be this can help :)
On Fri, Aug 4, 2017 at 3:08 PM, Damien Cassou <damien at cassou.me> wrote:
> Hi,
>
> I would like my add-on to add some text to the clipboard. The code of my
> extension to do that is quite complex:
>
> /**
> * Copy `text` to the clipboard
> */
> function copyText (text) {
> let textarea = document.createElement('textarea')
> textarea.textContent = text
>
> // hide the textarea
> textarea.setAttribute('style', 'height: 0 !important; width: 0
> !important; border: none !important; z-index: -9999999;')
> document.querySelector('body').appendChild(textarea)
>
> textarea.select()
> document.execCommand('Copy')
> textarea.remove()
> }
>
> Is there a simpler way?
>
> Thanks
>
> --
> Damien Cassou
> http://damiencassou.seasidehosting.st
>
> "Success is the ability to go from one failure to another without
> losing enthusiasm." --Winston Churchill
> _______________________________________________
> Dev-addons mailing list
> Dev-addons at mozilla.org
> https://mail.mozilla.org/listinfo/dev-addons
>
--
Cheers,
Trishul Goel
-------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/dev-addons/attachments/20170804/4b1c68e5/attachment-0001.html>
More information about the Dev-addons
mailing list