Just a thought, but would using an IFRAME
over a DIV
essentially make that element isolated from the window in a way that slow scripts running in the IFRAME
wouldn't affect the other frames/window?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
In new 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
Yes for the first part, an iframe will "sort-of" isolate your window from the script in the iframe. However, the parent window can still be accessed via
window.parent
.For the second part: No, it will not make it so slow scripts in the iframe won't affect other frames/windows. Your main window object and its child nodes all run in the same thread. JavaScript is single threaded [Ignore webworkers in this case, you can't pass dom elements between them anyway], so the only reason you can access the parent-window/child-iframe's window object is because they're on the same thread.
To provide a quick example:
src="iframe.html"
window.onload = function(){ while(1){} };
Source:
I tried getting multithreading like this too. Learned the hard way =)