IFrame contentDocument Property
Definition and Usage
contentDocument
The property returns the document generated by the frame or iframe element. Document Object.
This property can be used in the host window to access properties of frame or iframe elements that belong to it. Document Object.
Note:For security reasons, content from another document can only be accessed when the two documents are located in the same domain.
Instance
Example 1
An example of how to change the background color of the document contained within an iframe across different browsers:
var x = document.getElementById("myframe"); var y = (x.contentWindow || x.contentDocument); if (y.document) y = y.document; y.body.style.backgroundColor = "red";
Example 2
Here is another example of how to access the document of an iframe to change the background color:
var x = document.getElementById("myframe"); var y = x.contentDocument; y.body.style.backgroundColor = "red";
Syntax
iframeObject.contentDocument
Technical Details
Return Value: | Reference to the document object. If there is no document, the return value is null. |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |