Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!