Frame/IFrame contentWindow 屬性

2018-12-22 11:00 更新
Frame/IFrame 對象參考手冊 Frame/IFrame 對象


定義和用法


contentDocument 屬性能夠以 HTML 對象來返回 iframe 中的文檔。

可以通過所有標(biāo)準(zhǔn)的 DOM 方法來處理被返回的對象。


語法


frameObject.contentWindow

或者

iframeObject.contentWindow

瀏覽器支持


Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持 contentWindow 屬性



實例


實例

以下實例通過瀏覽器展示了如何改變iframe包含的文檔背景顏色:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool(w3cschool.cn)</title>
<script>
function changeStyle(){
    var x=document.getElementById("myframe");
    var y=(x.contentWindow || x.contentDocument);
    if (y.document)y=y.document;
    y.body.style.backgroundColor="#0000ff";
}
</script>
</head>
<body>
    
<iframe id="myframe" src="demo_iframe.htm">
<p>你的瀏覽器不支持iframes。</p>
</iframe>
<br><br>
<input type="button" onclick="changeStyle()" value="修改背景顏色">

</body>
</html>

嘗試一下 ?


Frame/IFrame 對象參考手冊 Frame/IFrame 對象
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號