Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
¿Cómo usar JavaScript para completar la función de copia?

Soy nuevo en el programa! Quiero implementar una función, haga clic en el botón para copiar la URL en onclick al portapapeles para que el usuario la pegue en otro lugar, pero no sé cómo implementar este requisito, realmente necesito la ayuda de todos, gracias a todos.

 function copyJoblink(joblink){ let joblink = "https://chickpt.com.tw/dl?tp=4&um=1&ti={{$formatted_job['id']}}&e=share_job" window.getSelection().selectAllChildren(joblink); document.execCommand('copy') }
 a{ display: block; width: 60px; height: 60px; background-color: #ccc; line-height: 60px; text-align:center; }
 <a href="javascript:;" class="job_info_share_paperlink" onclick="copyJoblink('https://chickpt.com.tw/dl?tp=4&um=1&ti={{$formatted_job['id']}}&e=share_job')">copy</a>

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Con preventDefault() , puede usar el href de su enlace porque la acción predeterminada no debe tomarse como lo haría normalmente.

Luego, deberá usar la API del portapapeles y clipboard.writeText() para que funcione.

 function clipboardCopy(event) { event.preventDefault(); navigator.clipboard.writeText(event.target.getAttribute('href')).then(() => { console.log('clipboard saved url :' + event.target.getAttribute('href')); }, () => { console.log('clipboard saved url : failed...'); }); }
 a{ display: block; width: 60px; height: 60px; background-color: #ccc; line-height: 60px; text-align:center; }
 <a href="https://chickpt.com.tw/dl?tp=4&um=1&ti={{$formatted_job['id']}}&e=share_job" class="job_info_share_paperlink" onclick="clipboardCopy(event)">copy</a>

over 4 years ago · Santiago Trujillo Denunciar

0

 function copyJoblink(jobLink) { navigator.clipboard.writeText(jobLink); /* Alert the copied text */ alert("Copied the text: " + jobLink); }
 a{ display: block; width: 60px; height: 60px; background-color: #ccc; line-height: 60px; text-align:center; }
 <a href="javascript:;" class="job_info_share_paperlink" onclick="copyJoblink('https://chickpt.com.tw/dl?tp=4&um=1&ti={{$formatted_job[\'id\']}}&e=share_job')">copy</a>

over 4 years ago · Santiago Trujillo Denunciar

0

Puede hacerlo como a continuación Probado en Chrome y Microsoft Edge y funciona bien:

 function copyJoblink(joblink) { const input = document.createElement('input'); input.value = joblink; document.body.appendChild(input); input.focus(); input.select(); document.execCommand("copy"); document.body.removeChild(input); alert('Link Copied: ' + joblink); }
 a { display: block; width: 60px; height: 60px; background-color: #ccc; line-height: 60px; text-align:center; }
 <a href="javascript:void(0);" class="job_info_share_paperlink" onclick="copyJoblink('https://chickpt.com.tw/dl?tp=4&um=1&ti={{$formatted_job[\'id\']}}&e=share_job')">copy</a>

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda