IFrame contentWindow Property
Definition and Usage
contentWindow
The property returns the Window Object.
Tip:Through Window ObjectYou can access Document Objectand then access any element of the document.
Instance
Example 1
Cross-browser examples on how to change the background color of the document contained within an iframe:
var x = document.getElementById("myframe"); var y = (x.contentWindow || x.contentDocument); if (y.document) y = y.document; y.body.style.backgroundColor = "red";
Example 2
Another example of how to access the document of an iframe to change the background color:
var x = document.getElementById("myframe"); var y = x.contentWindow.document; y.body.style.backgroundColor = "red";
Syntax
iframeObject.contentWindow
Technical Details
Return Value: | Reference to the Window Object. |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |