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

316
Visualizações
Get selection offset of string in textarea containing multibyte characters

It seems that the selectionStart and selectionEnd properties of a textarea element in Javascript are not multi-byte safe, returning the wrong values for the selection offset when multibyte characters are present:

https://jsfiddle.net/skeets23/wdnrj89k/16/

Is there any way to work around this and get the correct selection offsets?

My usage case is: I want to allow the user to save a section of "highlighted" text in a given paragraph. So they can select text and press "save", and it sends the "start" and "end" value of their selection to the back end (which is already multi-byte compatible (PHP, so mb_* functions))

I tried disabling multi-byte compatibility on the back end in hopes that at least the front end and the back end would treat multi-bite strings in the same way, but that wasn't the case... it gave me garbled text :P

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