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

94
Vistas
How do I copy to the clipboard in JavaScript? tell me

i used this code

const copyBtns = [...document.getElementsByClassName('copy')]
  copyBtns.forEach(btn=> btn.addEventListener('click', ()=>{
    content = btn.getAttribute('data-content')
    navigator.clipboard.writeText(content)
    btn.textContent = "تم النسخ"
  }))

copy not working on click in mobile, and it's working with any computer. what is the solution?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I've used this approach in the past for web apps, which uses jQuery to construct a hidden <input> field and copy the text from there. This seems to work well cross-platform, including Android and iOS devices.

const temp = $('<input>');
$('body').append(temp);
temp.val('YOUR STRING HERE').select();
document.execCommand('copy');
temp.remove();

I suspect the reason your code is not working is because the mobile browser does not have access to (or support for) clipboard. Can I Use? is a great resource to determine support for CSS/HTML and other browser APIs .

about 4 years ago · Juan Pablo Isaza 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