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 物件,您可以訪問 document 物件,然後訪問 document 的任何元素)。
瀏覽器支援
屬性 | |||||
---|---|---|---|---|---|
contentWindow | 是 | 是 | 是 | 是 | 是 |
語法
iframeObject.contentWindow
技術詳情
返回值 | 指向視窗物件的引用 |
---|
更多示例
示例
另一個訪問 iframe 文件以更改背景顏色的示例
var x = document.getElementById("myframe");
var y = x.contentWindow.document;
y.body.style.backgroundColor = "red";
自己動手試一試 »
❮ IFrame 物件