在js中,我们时常用到用iframe做系统框架,在子页面也,父页面之间的值传递是一个问题,下面是js获取父窗体和子窗体的对象js:
1.在iframe子页面中获取父页面的元素:
a>window.parent.document这个是获取父页面document中的对象;
- var reportRadio = window.parent.document.getElementById("reportRadio").value;
b>如果要获取父页面js中的方法:window.parent.xxxx();xxxx()为方法;
2.在父页面中获取iframe子页面中的元素:
a>
var child = document.getElementById("mainFrame").contentWindow;//mainFrame这个id是父页面iframe的id
- <span style="white-space:pre"> </span>child.document;//获取子页面中的document对象
js怎么获取iframe的src链接到的页面内的元素,并绑定事件
- window.onload=function(){
- document.getElementById('iframe1').contentWindow.document.getElementById('btn1').onclick=function(){alert(123);return false;};
- };
IFrame下父页面调用子页面的JS方法
- parent.frames["frameName"].window.functionName();
frameName:IFrame的ID;
funtionName:子页面中JS方法名;
var obj = parent.frames["frameName"].window;
在父页面访问子页面中某个控件如:obj.document.getElementByIdx_x('clientID')
子页面刷新父页面:top.window.location.replace(Url);