Latest web development tutorials

HTML DOM Frame / IFrame contentDocument property

Frame / IFrame Object Reference Frame / IFrame objects

Definition and Usage

contentDocument property to accommodate the HTML returned object framework document.

Can handle objects are returned by all the standard DOM methods.

Note: Due tosecurity reasons, the content of the document can only be accessed by another document under the same domain name.

grammar

frameObject.contentDocument

或者

iframeObject.contentDocument


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support contentDocument property

!Note: If you specify a DOCTYPE, Internet Explorer 8 and later support contentDocument property, use the other version of IE contentWindow property.


Examples

Examples

Browser example shows how to modify the iframe document background color:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</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>

try it"


Frame / IFrame Object Reference Frame / IFrame objects