Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Frame/IFrame contentWindow property

Frame/IFrame contentWindow property

Frame/IFrame Object Reference Frame/IFrame Object


Definition and Usage

The contentWindow property can return the document in the iframe as an HTML object.

The returned object can be processed using all standard DOM methods.

Syntax

frameObject.contentWindow

or

iframeObject.contentWindow


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the contentWindow property


Example

Example

The following example demonstrates through a browser how to change the background color of the document contained in an iframe:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>

Runoob Tutorial(runoob.com)

title

<

script

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=">

Modify Background Color

"

body

html

Try it »


Frame/IFrame Object Reference Frame/IFrame Object