Window parent 属性
实例
更改 <iframe> 元素的父文档的背景色
<!DOCTYPE html><html><body><iframe id="myframe" src="demo_iframe2.htm" width="100%" height="500" style="background:#f1f1f1;"><p>您的浏览器不支持 iframes.</p></iframe><p>单击 iframe 内的按钮以更改 iframe 父文档的背景色。</p></body></html>
定义与用法
parent 属性返回当前窗口的父窗口。
此属性是只读的。
浏览器支持
| 属性 | |||||
|---|---|---|---|---|---|
| parent | Yes | Yes | Yes | Yes | Yes |
语法
window.parent
技术细节
| 返回值: | 当前窗口的父窗口对象 |
|---|
更多实例
实例
打开新窗口时弹出父窗口的位置提示框:
<!DOCTYPE html><html><body><p>单击该按钮可在打开新窗口时弹出父窗口的位置提示框。</p><button onclick="myFunction()">Try it</button><script>function myFunction() {window.open("", "", "width=200, height=100");alert(window.parent.location);}</script></body></html>