# 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>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/chapter1/11bi-ji/19iframe/192iframe-contentwindow-property.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
