Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
HTML copy to clipboard button is not working

I'm trying to do a button to copy a link (www.google.com) to the clipboard, but it's not working. My code is:

<script type='text/javascript'>
    function myFunction() {
      /* Get the text field */
      var copyText = document.getElementById("www.google.com");
    
      /* Select the text field */
      copyText.select();
      copyText.setSelectionRange(0, 99999); /* For mobile devices */
    
       /* Copy the text inside the text field */
      navigator.clipboard.writeText(copyText.value);
    
      /* Alert the copied text */
      alert("Copied link!");
    }
</script>

And the button:

<button onclick='myFunction()'>Clik to copy the Link</button>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

try this with async function and await

async function copyGoogleLink(){
    await navigator.clipboard.writeText('https://www.google.com')
    .then(() => console.log('Copied'));
}

use this with Event Listener

about 4 years ago · Juan Pablo Isaza Relatório

0

This will help you


function copyToClipboard(text) {
  if (navigator.clipboard) {
    return navigator.clipboard.writeText(text);
  }

  const element = document.createElement('span');
  element.textContent = text;
  element.style.whiteSpace = 'pre';
  document.body.appendChild(element);
  const selection = window.getSelection();
  const range = document.createRange();
  selection.removeAllRanges();
  range.selectNode(element);
  selection.addRange(range);
  document.execCommand('copy');
  selection.removeAllRanges();
  document.body.removeChild(element);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda