jsp子页面(iframe)获取父页面(在另一个页面中用iframe)元素的方法

时间:2023-01-12 21:11:02

1.有一个页面myjsp.jsp

2.父页面包含在myjsp.jsp中:

<iframe id=“fatherFrame”  src="../fatherjsp.jsp"></iframe>

<iframe id=“fatherFrame2”  src="../fatherjsp2.jsp"></iframe>

3.在fatherjsp.jsp中包含子页面如:

<iframe id=“sonFrame”  src="../sonjsp.jsp"></iframe>

4.在sonjsp.jsp获取div的属性方法:

parent.frame['fatherFrame'].window.document.getElementById('mydiv');

这样写也不错:

parent.document.frame['fatherFrame'].document.getElementById('mydiv');