blob: 828bbdccc5943a6a7b865bf65705716f54de3ccd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
---
title: HTMLIFrameElement.contentWindow
slug: Web/API/HTMLIFrameElement/contentWindow
translation_of: Web/API/HTMLIFrameElement/contentWindow
---
<div>{{APIRef("HTML DOM")}}</div>
<p><span class="seoSummary"><strong><code>contentWindow</code></strong> 属性返回当前<a href="/en-US/docs/Web/API/HTMLIFrameElement">HTMLIFrameElement</a>的<a href="/en-US/docs/Web/API/Window">Window</a>对象. 你可以使用这个<code>Window</code> 对象去访问这个iframe的文档和它内部的DOM. 这个是可读属性, 但是它的属性像全局<code>Window</code> 一样是可以操作的. </span></p>
<h2 id="关于contentWindow的示例">关于contentWindow的示例</h2>
<pre class="brush: js">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.
</pre>
<h2 id="规范"> 规范</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('HTML WHATWG', '#dom-iframe-contentwindow', 'HTMLIFrameElement: contentWindow')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("api.HTMLIFrameElement.contentWindow")}}</p>
|