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

71
Visualizações
iFrame CSS injection loading priority

I'm trying to inject some CSS into an iFrame and it works fine except there is a delay before the new CSS takes effect, so you get a page that loads one theme and then changes color. It's only visible for a second, but it's annoying. Is there any way to delay the iFrame render until that CSS is applied? I add a script after the CSS, but seems that since I'm injecting this into the DOM, it renders then re-renders. I've tried using readyState interactive and complete to get it before load, but no luck and not sure how to delay it. Also tried addEventListener("load").

const frame_doc = document.getElementById("iframe").contentDocument;
function setFrameClass(light) {
    if (light) {
        frame_doc.body.classList.remove("dark")
    } else {
        frame_doc.body.classList.add("dark")
    }
}
themeSwitch.addEventListener('change', function () {
    setFrameClass(this.checked, frame_doc.body)
});
frame_doc.onreadystatechange = function () {
    if (frame_doc.readyState === 'interactive') {
        let link = frame_doc.createElement('link');
        link.rel = 'stylesheet';
        link.type = 'text/css';
        link.href = new URL('rootstatic/css/dark.css', window.location.origin).href;
        link.media = 'all';
        frame_doc.head.appendChild(link);
        let s = frame_doc.createElement("script");
        s.type = "text/javascript";
        s.src = new URL('rootstatic/js/dark-mode.js', window.location.origin).href;
        frame_doc.head.appendChild(s);
        setFrameClass(themeSwitch.checked)
    }
}
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