Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

332
Vistas
Get position of cursor when highlight the text

I need to create a Chrome Extension which people can use to look up words. And I have found that I use double-click method like when I want to find meaning of a word I just double click and then the notification will appear. (The image below is my Chrome Extension.)

enter image description here.

  • However, I find it is difficult for user to find meaning of pharsal verb, collocation and sentence.
  • So come up with an idea that I can get the position of cursor when user select text and to the last letter of this text I get the position.

enter image description here

  • In addition, I also have found many other Chrome extensions support this feature and they are so great!. One of them is "Edge Translate". When I higlight a text and then I release the mouse it appears a little popup ball then I click to this ball it appears panel. This is their extension: https://chrome.google.com/webstore/detail/edge-translate/bocbaocobfecmglnmeaeppambideimao?hl=en

enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

To get the text selected you could use this function, then remove the dots, and other characters you are not interested in and split the selected text by spaces to get the last word. (also you don't need the cursor coordinates for it, so you could remove this piece. of the code)

  let hasSelection = false;
  function showCoordsForMouseUp(event) {
      const selection = window.getSelection().toString()
      hasSelection = selection.length;
      if (hasSelection) {
          const x = event.clientX;
          const y = event.clientY;
          const coords = `X coords: ${x} , Y coords: ${y}`;
          console.log(`${coords} - ${selection}`)
      } else {
          console.log('No text selected')
      }
  }

  document.onmouseup = showCoordsForMouseUp;
about 4 years ago · Juan Pablo Isaza Denunciar

0

Thanks for your contribution, I have found the solution with onMouseUp Event.

document.onmouseup = function F(e) {
  x = e.pageX;
  y = e.pageY;
  if (window.getSelection().toString() != "") {
    console.log("X: " + x + "Y: " + y);
  }
}
<p>
  Flower, flowers.
</p>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda