Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!