--- title: HTMLIFrameElement.contentWindow slug: Web/API/HTMLIFrameElement/contentWindow translation_of: Web/API/HTMLIFrameElement/contentWindow ---
contentWindow 属性返回当前HTMLIFrameElement的Window对象. 你可以使用这个Window 对象去访问这个iframe的文档和它内部的DOM. 这个是可读属性, 但是它的属性像全局Window 一样是可以操作的.
var x = document.getElementsByTagName("iframe")[0].contentWindow;
//x = window.frames[0];
x.document.getElementsByTagName("body")[0].style.backgroundColor = "blue";
// this would turn the 1st iframe in document blue.
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('HTML WHATWG', '#dom-iframe-contentwindow', 'HTMLIFrameElement: contentWindow')}} | {{Spec2('HTML WHATWG')}} |
{{Compat("api.HTMLIFrameElement.contentWindow")}}