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

166
Views
Detect if user is using mobile iOS

I have written a function to copy text from a textarea but I need to have a particular code block executed if the user is using an apple mobile device.

I tried the following statement

if (navigator.userAgent.match(/iphone|ipod|ipad/)) {
 // code
}

but it doesn't seem to work very well.

Do you have any suggestions?

/* Full code */

function copy(copyText) {
  if (navigator.userAgent.match(/iphone|ipod|ipad/)) {
    // handle iOS devices
    copyText.contenteditable = true;
    copyText.readonly = false;

    var range = document.createRange();
    range.selectNodeContents(input);

    var selection = window.getSelection();
    selection.removeAllRanges();
    selection.addRange(range);
    input.setSelectionRange(0, 999999);
  } else {
    // other devices are easy
    copyText.select();
  }
  document.execCommand("copy");
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Detecting a mobile browser

Not sure if this is what youre looking for but it looks like might have the answer to your question?

Using navigator.userAgentData You may also use navigator.userAgentData.mobile, but userAgentData is still experimental, so it is not recommended for use in production.

const isMobile = navigator.userAgentData.mobile;

That part might be of use

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!