HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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

Internet Explorer Firefox Opera Google Chrome Safari

The contentWindow property is supported in all major browsers.


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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE