IFrame isolation
2 answers
Yes for the first part the iframe will "sort" isolate your window from the script in the iframe. However, the parent window can be accessed through window.parent
.
For the second part: No, this will not prevent slow scripts in the iframe from affecting other frames / windows. The main window object and its child nodes work in the same thread. JavaScript is single threaded [Ignore the webmasters in this case, you can't skip dom elements in between anyway], so the only reason you can access the parent-window / child-iframe window object is because they are in the same thread.
To provide a quick example:
- Create a page named main.html
- This page has an iframe
src="iframe.html"
- Next to the iframe, click the button with whatever text you need, I don't care.
- In iframe.html,
window.onload = function(){ while(1){} };
- Access to iframe.html. You will notice that when you hover your mouse over the button, it doesn't respond / does not redraw. This is because the browser is frozen.
Source:
I tried to get multithreading too. Learned the hard way =)
+7
a source to share