IFrame contentWindow 属性
实例
关于如何更改 iframe 中包含的文档的背景颜色的跨浏览器示例:
var x = document.getElementById("myframe");
var y = (x.contentWindow || x.contentDocument);
if (y.document)y = y.document;
y.body.style.backgroundColor = "red";亲自试一试 »定义和用法
contentWindow 属性返回由 iframe 元素生成的 Window 对象(通过 window 对象,您可以访问文档对象,然后访问文档的任何一个元素)。
浏览器支持
| 属性 | |||||
|---|---|---|---|---|---|
| contentWindow | Yes | Yes | Yes | Yes | Yes |
语法
iframeObject.contentWindow
技术细节
| 返回值: | 对窗口对象的引用 |
|---|
更多实例
实例
另一个如何访问 iframe 的文档以更改背景颜色的示例:
var x = document.getElementById("myframe");
var y = x.contentWindow.document;
y.body.style.backgroundColor = "red";亲自试一试 »