HTML
CSS
JS
Edit on Codewith.it
<div> <textarea id="area">Ciao mondo!</textarea> <br/> <button onclick="copia('area')">copia</button> </div>
#area { width:200px; height:100px; }
function copia(testo) { var input = document.createElement('input'); var area = document.getElementById(testo).value; input.setAttribute('value', area); document.body.appendChild(input); input.select(); var risultato = document.execCommand('copy'); document.body.removeChild(input); alert('testo copiato: '+ area); return risultato; }