简体   繁体   中英

How to use JavaScript to copy the text in a textarea to clipboard in Chrome?

I have a textarea tag and have a button. What I want is when I click the button, the text in that textarea will be copied into my clipboard.

I am using this in a Chrome Extension.

Thanks for any kind of help!

To copy text ...

function CopyToClipboard(text) {
    Copied = text.createTextRange();
    Copied.execCommand("Copy");
}

To get the text ...

textareaObject.value="text"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM