在此过程中,我发现使用iframe是一种“糟糕的做法”。

这是真的吗?使用它们的利与弊是什么?


当前回答

从可用性的角度来看,最初的框架集模型(框架集和框架元素)非常糟糕。IFrame是后来的发明,它不像最初的框架集模型那样有那么多问题,但它确实有它的缺点。

如果您允许用户在IFrame内部导航,那么链接和书签将不能正常工作(因为您收藏了外部页面的URL,而不是IFrame的URL)。

其他回答

从可用性的角度来看,最初的框架集模型(框架集和框架元素)非常糟糕。IFrame是后来的发明,它不像最初的框架集模型那样有那么多问题,但它确实有它的缺点。

如果您允许用户在IFrame内部导航,那么链接和书签将不能正常工作(因为您收藏了外部页面的URL,而不是IFrame的URL)。

iframes肯定有用处。你还会怎么把天气网络小部件放在你的页面上?唯一的另一种方法是获取XML并解析它,但是当然,您需要条件来抛出pertenant天气图形……不太值得,但如果你有时间,会更干净。

Based on my experience a positive side for iframe are when calling third party codes, that may involve calling a javascript that calls a has a Document.write(); command. As you may know, these commands cannot be called asynchronously due to how it is parsed (DOM Parser etc). An example of this is http://sourceforge.net/projects/phpadsnew/ I've made use of iframes to help speed up our site as there were multiple calls to phpadsnews and the site was waiting for the response before proceeding to render different parts of the page. with an iframe I was able to allow the site to render other parts of the page and still call the Document.write() command of phpads asynchronously. Preventing and js locking.

值得注意的是,无论用户的互联网连接速度或iframe的内容如何,iframe都会导致页面下载速度出现轻微(0.3秒左右)但明显的放缓。这是您在本地测试时不会看到的。实际上,添加到页面中的任何元素都是如此,但iframes似乎更糟糕。

当您的主页以HTTP协议加载,而页面的某些部分需要以HTTPS协议工作时,iFrame可以轻松击败jsonp。

特别是,如果你的数据类型不是原生的json,需要在服务器上翻译成json,并在客户端翻译回复杂的html。

所以iFrame并不是邪恶的。