0

document has the execCommand function, in it there is copy property:

document.execCommand('copy');

But I want to copy a special text, how can I realize it?

Such as:

var text = "abc123"
document.execCommand('copy', xxx) // or whatever to copy the text to the clipboard.
Nope
  • 21,907
  • 7
  • 45
  • 72
qg_java_17137
  • 3,134
  • 7
  • 38
  • 70
  • `document.execCommand("copy")` copies the selected text to the clipboard. Are you saying you want to copy something else to the clipboard? – Reinstate Monica Cellio May 22 '18 at 09:54
  • You can't, `execCommand('copy')` copies the selected content of a current editable element, it is not capable to copy some text from a JS variable. Except the case you can add the "special text" to an element, and then select the text and exec. – Teemu May 22 '18 at 09:54

0 Answers0