Skip to content

Instantly share code, notes, and snippets.

@guibranco
Created November 9, 2017 13:18
Show Gist options
  • Save guibranco/8a30b6f50e382959594143beb8684c23 to your computer and use it in GitHub Desktop.
Save guibranco/8a30b6f50e382959594143beb8684c23 to your computer and use it in GitHub Desktop.
Faz a cópia de um valor de um textarea via JS - Resposta para https://www.facebook.com/groups/desenvolvimentowebbrasil/permalink/1488102017942520/
<!DOCTYPE html>
<textarea id=t></textarea>
<br />
<button onclick="copy()">Copiar</button>
<div style='background:#FCF;' id='log'></div>
<script>
var log = document.getElementById('log');
function copy() {
var t = document.getElementById('t')
t.select()
try {
var s = document.execCommand('copy')
log.innerHTML = 'Resultado: ' + (s ? '' : 'não ') + 'copiou o texto <br />' + log.innerHTML;
} catch (err) {
log.innerHTML = 'Erro: ' + err.message + '<br />' + log.innerHTML;
}
t.innerHTML = ''
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment