Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda