Select and Copy Textarea Text To ClipBoard
Per facilitare un utente nel copia e incolla spesso è utile implementare il seguente snippet che seleziona e copia negli appunti (clipboard) il testo all’interno di una textarea.
<html>
<body>
<form id="frm">
![]()
<textarea name="txt" cols="30" rows="5">Questo testo verrà copiato negli appunti</textarea>
<br><br>
Versione Internet Explorer
<a onclick="copiaIE();" href="#">Select all and copy with IE</a>
</form>
<script language="JavaScript">
function copiaIE(){
frm.txt.select();
therange=frm.txt.createTextRange();
therange.execCommand('Copy');
alert('copiato negli appunti');
}
</script>
</body>
</html>
Valido per Internet Explorer.
Download source: js_select_and_copy_to_clipboard.zip (412,00 bytes)
Lascia un commento