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

109
Vistas
JavaScript bookmarklets don't modify the correct document.activeElement?

I am trying to use a bookmarklet to modify the content of the currently-active textbox.

If I write let a = document.activeElement; console.log(a), then in my console, I see the currently-active textbox correctly printed to the console. If, in the console, I then write a.value = "hello", the content of that textbox changes exactly as expected.

If I write let a = document.activeElement; a.value = "hello" in my bookmarklet, however, it replaces the entire document with the text node "hello." Same with document.activeElement = "hello".

I am guessing that once the bookmarklet is clicked, the entire document or browser window becomes the activeElement. But if that's true, I'm not sure why the correct node would be referenced and preserved in the first case. Nor can I find any way to preserve the reference to do anything with outside of the console.

Is it possible to do this?

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

0

I'm not sure it's possible to detect focus after it has been changed, in this case, by clicking the bookmarklet. Although more annoying, you could check for focus changes with the onfocus event, and only then use document.activeElement.

MDN Docs — onfocus

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