如果A窗口中调用js,window.open("B窗口");

那么在B窗口中调用js, window.opener可以得到A窗口。

 

parent表示父窗口,比如一个A页面利用iframe或frame调用B页面,那么A页面所在窗口就是B页面的parent。在JS 中,window.opener只是对弹出窗口的母窗口的一个引用。比如:a.html中,通过点击按钮等方式window.open出一个新的窗口 b.html。那么在b.html中,就可以通过window.opener(省略写为opener)来引用a.html,包括a.html的 document等对象,操作a.html的内容。
假如这个引用失败,那么将返回null。所以在调用opener的对象前,要先判断对象是否为null,否则会出现“对象为空或者不存在”的JS错误。

 

如果一个frameset中有多个frame和framset,

在获取子frameset的时候,知道父frameset可以直接  .framset的name属性;

而且用. name属性的方式可以实现跨层获取。

例如:

<frameset rows="20,40,50" cols="*" name="main">
 <frame src="" name="chid1"/>
 <frame src="" name="child2"/>
 <frameset rows="*" cols="50%,*" name="child3">
  <frame src="a.html" name="child4"/>
  <frame src="b.html" name="child5"/> 
 </frameset>
 </frameset>

当在b.html中使用js获取child1时,可以parent.child1

当在b.html中使用js获取child4时,可以parent.child4