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

332
Visualizações
.contentDocument on object-tag returns null (sometimes)

My problem is that based on how I view the project I've built, objectRef.contentDocument sometimes returns a proper Document but other times null. This seems to be based on whether I serve the project from a webserver or simply open the HTML as file.

Let's get accustomed with the code though - what I'm trying to build is an image-carousel with SVG-icons that change color based on scroll position as navigation-buttons:

<div class="album-carousel">
    <div class="cover-container">
        <div class="cover"></div>
        ...
    </div>
    <object class="arrow left" data="assets/svg/arrow.svg" type="image/svg+xml"></object>
    <object class="arrow right" data="assets/svg/arrow.svg" type="image/svg+xml"></object>
</div>

When inspecting this in Chrome, the following actually gets rendered - as you see, a Document is created within the object-tag:

inspector content

I then get a reference to the album-carousel in JS and create a new instance of my own class, only after the DOM is fully loaded:

class AlbumCarousel {
  elementRef;
  arrowLeft;
  arrowRight;

  constructor(elementRef, scrollBy = 3) {
    this.elementRef = elementRef;
    this.arrowLeft = elementRef.children[1];
    this.arrowRight = elementRef.children[2];

    const scrollRight = () => {
      // irrelevant code
    }

    this.arrowRight.contentDocument.addEventListener("click", scrollRight);

    if (this.compoundWidth > Number.parseInt(getComputedStyle(this.albumContainerRef).width)) {
      this.arrowRight.contentDocument.children[0].style.fill = colors.base;
    }
  }

}

this.arrowRight.contentDocument.addEventListener(...) will throw an error when opened as file, however not when opened through IntelliJ's built-in local webserver - or am I searching in the wrong place here?

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