The following code copies text from an input element to the computers clipboard. The actual element is hidden. Adjust the code as needed for use in copy to the clipboard use cases:
<style>
.outer {
overflow: hidden;
position: relative;
}
.inner {
position: absolute;
height: 100px;
width: 100px;
right: -50px;
top: 50px;
}
</style>
<img onclick="copyTextToClipboard()" src="https://img.icons8.com/android/24/000000/share.png">
<div class="outer">
<div class="inner">
<input type="text" value="Hello World xxxx paul" id="clipboardText">
</div>
</div>
<script>
function copyTextToClipboard() {
var copyText = document.getElementById("clipboardText");
copyText.select();
copyText.setSelectionRange(0, 99999)
document.execCommand("copy");
alert("Product link copied to clipboard: " + copyText.value);
}
</script>