IFrame contentWindow Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:IFrame


The contentWindow property returns the Window object generated by an iframe element.

Return Value

A reference to the window object

The following code shows how to how to change the background color of the document contained in an iframe:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<iframe id="myframe" src="http://java2s.com"></iframe>

<p id="demo"></p>

<button onclick="myFunction()">Test</button>

function myFunction() {//from  w  ww . ja va 2s .c o  m
    var x = document.getElementById("myframe");
    var y = x.contentDocument;
    y.body.style.backgroundColor = "red";


Related Tutorials