I'm trying to understand why this code does not work.
What i'm trying to accomplish is to copy into clipboard the current url, so as a workaround i try to create an hidden input in which i pass the current location, but i have no luck.
here an example of what i've tried so far:
var copyBtn = document.querySelector('#copy_btn');
copyBtn.addEventListener('click', function () {
var input = document.createElement('input');
input.style.display = "none";
input.setAttribute('value', document.location)
document.body.appendChild(input);
// select the contents
input.select();
document.execCommand('copy');
}, false);
<input id="copy_btn" type="button" value="copy">