> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/chapter1/11bi-ji/19iframe/192iframe-contentwindow-property.md).

# 1.9.2.IFrame contentWindow property

## 1.Introduction

* contentWindow可以回傳由IFrame產生的window object
* 藉由window object, 可以取得document object以及其任何一個element

## 2.Usage

* Example from [w3schools.com](https://www.w3schools.com/jsref/prop_frame_contentwindow.asp)

```
<!DOCTYPE html>
<html>
<body>

<iframe id="myframe" src="demo_iframe.htm"></iframe>

<p>Click the button to change the background color of the document contained in the iframe.</p>

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

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    var x = document.getElementById("myframe");
    var y = (x.contentWindow || x.contentDocument);
    if (y.document)y = y.document;
    y.body.style.backgroundColor = "red";
}
</script>

</body>
</html>
```
