W3Schools.com

Frame/IFrame contentWindow Property

Frame/IFrame Object Reference Frame/IFrame Object

Definition and Usage

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

Syntax

frameObject.contentWindow

or

iframeObject.contentWindow


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The contentWindow property is supported in all major browsers.


Example

Example

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript">
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>Your browser does not support iframes.</p>
</iframe>
<br /><br />

<input type="button" onclick="changeStyle()" value="Change background color" />

</body>
</html>

Try it yourself »


Frame/IFrame Object Reference Frame/IFrame Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE