The subject of iframes can become a little complicated there is much to write about with them when it comes to more advanced topics involving hidden iframes, and security concerns when with things like click jacking that ca be preformed with iframes. So in this post I will be sticking to just the basics for now as many of these other topics are matters for another post.
When working with an iframe that is hard coded into the html the process is to just gain a reference to it by using something like document.querySelector, document.getElementById, or any other means that will result in the creation of a reference to the hard coded iFrame element in the html of the page.
Once a reference to the iFrame is obtained it is possible to access the window object of that iFrame via the contentWindow property of the iFrame element. This works in much the same way as the window object of the page itself as such I can add content to the iFrame in the same manner as I would with the main window object. So there is getting at the window object of an iframe that is all ready there in the html, but then there is creating and injecting them also, so with that said lets look at the next section.
With this kind of approach you might have some html like this.
Never the less if the url is at the same domain, or if it is a url where this sort of thing will happen without issue then the following might work out okay.
To do so I just need to set the src attribute of the iframe to the url of the resource that I want to load and display in the iframe. If all goes well that alone should work, if not finding a solution to this is outside the scope of this post.
3 - Threading with an iframe will not result in a separate event loop, or ‘true threading’ as it is sometimes called
Here I have a page that is doing something that will take a little time that I will be saving as thread.html. This page can be loaded up by itself, however I intend to load it up in an iframe in a main html file that will open this file up via the src attribute. If an iframe where to get its own event loop, then the while loop taking a long time to count to a large number would not interfere with something else going on in the main page.
So no using an iframe is not an alternative to using web workers, if for some reason you want more than one event loop that is the way that it is done in a web browser.