I would like to have a specific string copied to the clipboard when clicking on a button. I do not want the string to be defined by the user (i.e. a text box or the like), but rather I want it to be defined in the code.
What I have is the following:
function yyy(){
var dummyContent = "this is to be copied to clipboard";
dummyContent.select();
document.execCommand('copy')
}
<input type="button" value="foobar" onclick=yyy(); />
A solution that works but only with a text box is the following:
function Copy()
{
var Url = document.getElementById("paste-box");
Url.value = "this is to be copied to clipboard";
Url.select();
document.execCommand("Copy");
}
<input type="button" value="Copy Link" onclick=Copy(); />
I would like the string "this is to be copied to clipboard" to be copied in the clipboard.
For the first one, nothing happens. For the second, it works but again there is a text box in the code.