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

155
Views
document.getSelection() not working on iOS chrome/safati

The problem that i'm having is that on iOS it seems like i cannot get the selection from the textarea. The same code on PC works well, and i can see the same text in the two alerts (range and sel, see code): on iOS unfortunately I see what i expect iun the 'range' alert but i see nothing in the 'sel' range (just the actual "sel :").
I tried almost every type of check possible and read all the existing documentations (i think at lest) before writing here so this is kinda my last resort

also the code is crappy, im sorry, just need this to work on mobile

                    // text area method
                    let textArea = document.createElement("textarea");
                    document.body.appendChild(textArea);
                    $(textArea).html(textToCopy);
                    // make the textarea out of viewport

                    textArea.style.position = "absolute";
                    textArea.style.opacity = 0; //tried without this, didnt work
                    textArea.style.left = "-999999px";
                    textArea.style.top = "-999999px";

                    //tried with this, didnt work
                    textArea.contentEditable = true;
                    textArea.readOnly = false;

                    $(textArea).css("user-select", "text");
                    $(textArea).css("-webkit-user-select", "text");

                    /*textArea.focus();*/

                    var selection = document.getSelection();
                    var range = document.createRange();
                    range.selectNodeContents(textArea);
                    alert("range: " + range)
                    selection.removeAllRanges();
                    selection.addRange(range);

                    alert("sel: " + selection.toString())

                    //tried with this, didnt work
                    /*textArea.setSelectionRange(0, 999999);*/

                    document.execCommand('copy')
                    textArea.remove();
about 4 years ago · Santiago Trujillo
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!