Copy String To Clipboard

Javascript

Copy a string to clipboard

Use this snippet to copy a string to the client's clipboard

javascript

function copyToClipboard(str) { var el = document.createElement('textarea'); el.value = str; el.setAttribute('readonly', ''); el.style = {position: 'absolute', left: '-9999px'}; document.body.appendChild(el); el.select(); document.execCommand('copy'); document.body.removeChild(el); }