iFrame 隔离
只是一个想法,但在 DIV
上使用 IFRAME
本质上会使该元素与窗口隔离,从而减慢 IFRAME
中运行的脚本> 不会影响其他框架/窗口吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,对于第一部分,iframe 会“某种程度上”将您的窗口与 iframe 中的脚本隔离开来。但是,仍然可以通过
window.parent
访问父窗口。对于第二部分:不,它不会使其如此慢,iframe 中的脚本不会影响其他框架/窗口。您的主窗口对象及其子节点都在同一线程中运行。 JavaScript 是单线程的[在这种情况下忽略 webworkers,无论如何你都无法在它们之间传递 dom 元素],因此你可以访问父窗口/子 iframe 的窗口对象的唯一原因是因为它们位于同一线程上。
提供一个简单的示例:
src="iframe.html"
window.onload = function(){ while(1){} };
来源:
我也尝试过像这样的多线程。艰难地学到了=)
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 =)
在新浏览器中,您可以使用沙箱属性将 iframe 与页面的其余部分隔离
http:// www.w3schools.com/tags/att_iframe_sandbox.asp
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