THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML

IFrame contentWindow Property

IFrame Object Reference IFrame Object

Example

A crossbrowser example on how to change the background color of the document contained in an iframe:

var x = document.getElementById("myframe");
var y = (x.contentWindow || x.contentDocument);
if (y.document)y = y.document;
y.body.style.backgroundColor = "red";
Try it Yourself »

Definition and Usage

The contentWindow property returns the Window object generated by an iframe element (through the window object, you can access the document object and then any one of the document's elements).


Browser Support

Property
contentWindow Yes Yes Yes Yes Yes

Syntax

iframeObject.contentWindow

Technical Details

Return Value: A reference to the window object

More Examples

Example

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";
Try it Yourself »

IFrame Object Reference IFrame Object