Created
November 9, 2017 13:18
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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