在对象(而不是iframe)中嵌入text/html

9 html iframe internet-explorer cross-browser cross-domain

<iframe data="/localfile.html" type="text/html" width="200" height="200"></iframe>
<iframe data="http://example.com/remotefile.html" type="text/html" width="200" height="200"></iframe>
<object data="/localfile.html" type="text/html" width="200" height="200"></object>
<object data="http://example.com/remotefile.html" type="text/html" width="200" height="200"></object>
Run Code Online (Sandbox Code Playgroud)

在除IE之外的每个浏览器下,所有这4个测试都有效.在IE 6和7下,最后一个失败并显示一个空帧.是否有一种解决方法允许IE在对象中加载外部html?

Not*_*tMe 6

有关如何在IE中使用Object的更多信息,请查看以下内容:http://aplus.rs/web-dev/insert-html-page-into-another-html-page/

它归结为IE与其他浏览器相比的差异.对于IE,您必须使用classid属性而不是type属性.例如(来自上面引用的网站):

<!--[if IE]>
<object classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" data="some.html">
    <p>backup content</p>
</object>
<![endif]-->

<!--[if !IE]> <-->
<object type="text/html" data="some.html">
    <p>backup content</p>
</object>
<!--> <![endif]-->
Run Code Online (Sandbox Code Playgroud)

请注意,classid特定于您尝试服务的内容类型.

  • 如果您尝试从远程服务器提取内容,Chris的解决方案在IE中不起作用 (2认同)