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

331
Vistas
.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 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