I am trying to simulate multi threading using an iframe but I have come across a situation which I do not know if it actually utilizes the iframe process (thread) on its own.
For instance, If I call a method which lays inside an iframe, will it run using the thread created by the iframe or will it run using the main parent window thread?
If it is the latter, then is it possible to change the scope so that the iframe calls the method (so that the program uses a different thread from that of the parent window)
EDIT: Maybe I should have been more clear on this but I do not want to use WebWorkers simply because I do not have access to the DOM elements.
To sum up the other answers: No, iFrames usually run in the same thread/process as the main page.
Multithreading is supported by all programming languages and platforms. But HTML never supported it. HTML programmers had to use setTimeout or setInterval to make the application behave like multithread application. But HTML5 provided built in API to support multithreading.
Thanks to recent advancements in the language--such as the Atomics and SharedArrayBuffers objects and Web Workers in the browser--JavaScript is now a multi-threaded language.
“Today's browsers are inherently single-threaded,” explained Stephen Reeder, Commercial Director at Ekioh. “So if you're running on multi-core silicon, you're only using one of those cores.” “With multi-tabbed browsing, each tab has its own thread.
If you want to run some background tasks just use WebWorkers.
Generally you don't need to multi thread js code. You should use event loops instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With