I'm trying to figure out, how to copy string and paste from JavaScript.
This code example:
function copyLink() {
var copyText = document.getElementById("myInput");
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
}
Copies from myInput value:
<input type="text" value="ttps://site.org/" id="myInput">
but I'm trying copy text from variable, not included to html value:
<button onclick="copyText()">Copy text</button>
which is in .js to allow user copy/paste:
function copyText() {
var text = "long text...";
...
}
It looks simple, but seems like I'm searching incorrectly, because I can't find the method.