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

125
Visualizações
how do i select an entire url address in contenteditable

in contenteditable, links don't work, so i'm thinking the best solution is to at least be able to select an entire url with one click or two clicks when the cursor is in any part of the url, then right-click and go to the site. is there a javascript solution to this, something similar to android phone's long-press-select and paste?

<div contenteditable="true">some text here, then the complete url https://gizmodo.com/e-ink-kaleido-3-gallery-3-foldable-color-e-readers-1848842166 but i just want to select the url with one or two clicks, how? </div>

contenteditable:

some text here, then the complete url https://gizmodo.com/e-ink-kaleido-3-gallery-3-foldable-color-e-readers-1848842166 but i just want to select the url with one or two clicks, how?
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could replace the url strings with anchor tags and attach an onclick listener to navigate to the url on click:

text.innerHTML = text.textContent.replace(/https*:\/\/[^\s]+/gmi, (match) => `<a style="cursor:pointer" href="${match}">${match}</a>`);

[...text.children].forEach(a => a.onclick = (e) => window.open(a.href))

text.onblur = e => {
e.target.innerHTML = e.target.textContent.replace(/https*:\/\/[^\s]+/gmi, (match) => `<a style="cursor:pointer" href="${match}">${match}</a>`);
[...text.children].forEach(a => a.onclick = (e) => window.open(a.href))
}
<div id="text" contenteditable="true">some text here, then the complete url https://gizmodo.com/e-ink-kaleido-3-gallery-3-foldable-color-e-readers-1848842166 i just want to select the url with one or two clicks, how? Another url here: https://gizmodo.com/e-ink-kaleido-3-gallery-3-foldable-color-e-readers-1848842166
</div>

(The navigation in the snippet iframe is prevented but it should work in a normal window)

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