Snippet javascript Copy to the clipboard with js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
function copyLinkPost(e) { const el = document.createElement('textarea'); let str = e.target.getAttribute('data-link-copy'); console.log(str); el.value = str; el.setAttribute('readonly', ''); el.style.position = 'absolute'; el.style.left = '-9999px'; document.body.appendChild(el); el.select(); el.setSelectionRange(0, 99999) document.execCommand("copy"); document.body.removeChild(el); console.log("Copied the text: " + el.value); } |