IFrame isolation

Just a thought, but using IFRAME

above DIV

will essentially make that element insulated from the window in such a way that slow scripts running in IFRAME

won't affect other frames / window?

+2


a source to share


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


In newer browsers, you can use the sandbox property to isolate the iframe from the rest of the page



http://www.w3schools.com/tags/att_iframe_sandbox.asp

+1


a source







All Articles