Frame/IFrame contentDocument property

HTML DOM Frame/IFrame contentDocument property Frame/IFrame object

Definitions and usages

The contentDocument property returns the document that the frame holds with html objects.

Returned objects can be processed through all standard DOM methods.

Note: For security reasons, the contents of a document can only be accessed through another document under the same domain name.

Grammar

frameObject.contentDocument

or

iframeObject.contentDocument


Browser support

HTML DOM Frame/IFrame contentDocument property HTML DOM Frame/IFrame contentDocument property HTML DOM Frame/IFrame contentDocument property HTML DOM Frame/IFrame contentDocument property HTML DOM Frame/IFrame contentDocument property

The contentDocument property is supported by all major browsers

Note: If specified! DoCTYPE, Internet Explorer 8 and later support the contentDocument property, and other versions of IE use the contentWindow property.


The browser example shows how to modify the background color Chinese iframe file:

<!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>

Try it out . . .


HTML DOM Frame/IFrame contentDocument property Frame/IFrame object