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

104
Visualizações
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 Respostas
Responde à pergunta

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 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