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

236
Visualizações
Opening and closing an iframe document within `onload`

Would there be any sort of issue or specification incompatibility caused by calling

 // assume iframe.contentWindow was checked beforehand and is defined
 iframe.contentWindow.document.open();
 iframe.contentWindow.document.close();

within the iframe onload function?

e.g.

iframe.onload = () => {
 // ...
 // assume iframe.contentWindow was checked beforehand and is defined 
 iframe.contentWindow.document.open();
 iframe.contentWindow.document.close();
}

The background to this is that when creating a friendly iframe, I want to get a reference to the iframe window and do certain operations with no / minimal writing to the iframe beforehand using document.write() and without having to use setTimeout (see https://bugs.chromium.org/p/chromium/issues/detail?id=978325 and https://bugs.chromium.org/p/chromium/issues/detail?id=961428 for why setTimeout would be needed)

The issue is that without calling open or when calling it prior to the onload function, the iframe location is set to about:blank (see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#opening-the-input-stream step 13). This can also be solved by adding a setTimeout after opening the document (outside of onload) at the cost of performance, which I would like to avoid.

The solution involving calling open and close within the onload function works on Chrome, Firefox and Safari, but JSDom considers the contentDocument to be null and the iframe itself to have no children when using this method (after manually simulating a call to onload, which is a separate issue, but might be related to the behavior)

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