IFrame contentWindow Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:IFrame

Description

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>
<html>
<body>

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

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

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

<script>
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";
}
</script>

</body>
</html>

Related Tutorials