Created
October 16, 2018 19:20
-
-
Save brunocarvalhodearaujo/ef3996d6b4fb6d70fd23d592c7f22f18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const copyTextareaBtn = document.querySelector('.btn-cp') | |
// quando o botão for clicado aciona o evento | |
copyTextareaBtn.addEventListener('click', event => { | |
// elemento como um input com o conteudo que deve ser copiado | |
const copyTextarea = document.querySelector('.copytextarea') | |
// seleciona o elemento | |
copyTextarea.select(); | |
try { | |
// executa a copia para a area de transferencia retornando um status | |
let successful = document.execCommand('copy') | |
// exibe uma mensagem com o status da copia | |
console.log('Copying text command was ' + successful ? 'successful' : 'unsuccessful'); | |
} catch (err) { | |
// caso ocorra uma falha no método de copia | |
console.log('Oops, unable to copy'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment