2020-10-19T23:00:00Z
On first run this code copies the string to the clipboard. On the clipboard should be “mystring123aaajj”.
The output on the console is truncated, it shows the partial code with the arrow for more of the code. But the output of the line ‘console.log(“result”,result)’ seems to be missing.
Now, if I try this code again (cntrl + enter in multiline mode) I get the partial code and arrow, and ‘result false’ and a warning error - ‘document.execCommand(‘cut’/‘copy’) was denied because it was not called from inside a short running user-generated event handler.’
Here is the code:
//works once in the console
function copy(text){
input=document.createElement(“input”)
input.innerHTML= text
document.body.appendChild(input)
input.select()
result=document.execCommand(“copy”)
console.log(“result”,result)
document.body.removeChild(input)
return result
}
myret=copy(“mystring123aaajj”)
////////
Works on first run but fails on second run?
This behaviour is different in Chrome.