js copy link to clipboard code example
Example 1: copy text to clipboard javascript
navigator.clipboard.writeText("Hello World");
Example 2: javascript copy to clipboard
<head><script>
function copyToCliBoard() {
var copyText = document.getElementById("myInput");
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
alert("Copied the text: " + copyText.value);
}
</script></head>
<body>
<input type="text" value="Hello World" id="myInput">
<button onclick="copyToCliBoard()">Copy text</button>
</body>