javascript: (function copyURL() { var node = document.createElement("url"); document.querySelector("html").appendChild(node); document.querySelector("url").innerText = decodeURI(document.URL) + " "; var copyText = document.querySelector("url"); copy(copyText); function copy(element) { var range, selection, worked; if (document.body.createTextRange) { range = document.body.createTextRange(); range.moveToElementText(element); range.select(); } else if (window.getSelection) { selection = window.getSelection(); range = document.createRange(); range.selectNodeContents(element); selection.removeAllRanges(); selection.addRange(range); } try { if (navigator.clipboard) { navigator.clipboard.writeText(range); } else { document.execCommand('copy'); } console.log("text copied"); } catch (err) { console.log("unable to copy text: " + err); } document.querySelector("html").removeChild(element); } })();