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

303
Visualizações
MS Word Online add-in: How to detect focus?

In developing a Microsoft Word Online add-in, my team needs to detect focus being gained/regained by the document (ETA: to trigger other functionality which depends on this knowledge). It appears that Microsoft has tightly locked down scriptability in this context--all window.on* functions are replaced by null, all error-handling code is deeply obfuscated, etc. Our efforts so far have been frustrated.

Simply setting window.onfocus to a new function causes the add-in to not load correctly, likely because it's triggering a code analyzer as unsafe, but hard to tell.

There is also nothing in the Microsoft Word Online JavaScript API which directly provides this functionality. Scripts can detect when the document selection has changed easily with a provided method, but that seems to be about it for documented functionality in this area. (Obviously simply sensing document changes will not work.)

What's the best approach to sensing document and/or window focus in this situation? Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The document.onvisibilitychange event can be used as a rough approximation of the required functionality.

document.onvisibilitychange = (ev) => {
  if (document.visibilityState == "visible") {
    // Handle pseudo-focus event
  }
  else {
    // Handle pseudo-blur event
  }
};

This may be combined as desired with with the Office Online API DocumentSelectionChanged event to refine further to sense when the cursor is placed within the Word document. (That is, fire focus-gained logic only when the Office DocumentSelectionChanged event is fired the first time after the browser document.onvisibilitychange event fired with document.visibilityState equal to "visible".)

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