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