iFrame隔离 [英] iFrame isolation

查看:797
本文介绍了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?

推荐答案

是的,对于第一部分,iframe将排序将窗口与iframe中的脚本隔离开来。但是,仍然可以通过 window.parent 访问父窗口。

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.

第二部分:不,它不会让它如此慢iframe中的脚本不会影响其他框架/窗口。您的主窗口对象及其子节点都在同一个线程中运行。 JavaScript是单线程的[在这种情况下忽略webworkers,你无法在它们之间传递dom元素],所以你可以访问parent-window / child-iframe的window对象的唯一原因是因为它们在同一个线程上。

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.

提供一个简单示例:


  • 创建一个名为main.html的页面

  • 在该页面中,有一个iframe src =iframe.html

  • 下一页到iframe,有一个按钮,你想要的任何文字,我不在乎。

  • 在iframe.html中, window.onload = function(){while(1){}};

  • 访问iframe.html。您会注意到,当您将鼠标光标放在按钮上时,它不会响应/重绘。这是因为浏览器被冻结了。

  • Create a page called main.html
  • In that page, have an iframe src="iframe.html"
  • Next to the iframe, have a button with whatever text you want, I don't care.
  • In iframe.html, window.onload = function(){ while(1){} };
  • Access iframe.html. You'll notice that when you put your mouse cursor over the button, it doesn't respond/redraw. This is because the browser is frozen.

资料来源:

我也试过这样的多线程。学到了很多东西=)

Source:
I tried getting multithreading like this too. Learned the hard way =)

这篇关于iFrame隔离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆