copy to clipboard function javascript html dom code example
Example 1: javascript copy to clipboard
function copyToClipboard(text) {
var input = document.body.appendChild(document.createElement("input"));
input.value = text;
input.focus();
input.select();
document.execCommand('copy');
input.parentNode.removeChild(input);
}
Example 2: how to access clipboard via js
navigator.clipboard.readText().then(clipText =>
document.getElementById("outbox").innerText = clipText);