I managed to copy text to the clipboard (without showing any text boxes) by adding a hidden input
element to body
, i.e.:
function copy(txt){_x000D_
var cb = document.getElementById("cb");_x000D_
cb.value = txt;_x000D_
cb.style.display='block';_x000D_
cb.select();_x000D_
document.execCommand('copy');_x000D_
cb.style.display='none';_x000D_
}
_x000D_
<button onclick="copy('Hello Clipboard!')"> copy </button>_x000D_
<input id="cb" type="text" hidden>
_x000D_