Web所有父窗体与子窗体的交互方法列举(子调用父窗体函数)

来源:互联网 发布:架子鼓教学软件 编辑:程序博客网 时间:2024/04/30 02:24

 

Web所有父窗体与子窗体的交互方法列举(子调用父窗体函数)

1>父窗体是使用window.open(url,name,feather)打开子窗体时,使用下面的方法获取。
调用父窗体函数:window.opener.Fun();
调用父窗体物件:window.opener.document.getElementById("txt_test").value

2>子窗体是IFrame的时候,直接用window.parent.Fun或window.parent.Obj

3>父窗体是使用window.showModalDialog(url,arguments,feather)打开子窗体时,使用下面的方法获取。
   1.体在Show子窗体的时候,把当前window对象(只要对象的话用window.document即可)当参数传到子窗体:
      方法如:window.showModalDialog(url,window,"dialogwidth=300px;")
    2.窗体获取这个window对象.var pWin=window.dialogArguments;
    3.同过pWin来调用父窗体函数。(例如 父窗体函数为pFun()); 
 var pwin = window.dialogArguments;
 if(pwin!=undefined){
 var codeStr = "pFun();"
 pwin.execScript(codeStr,"javascript");

当然上面的方法直接等价于pWin.pFun()

 

补充,今天项目上又用到了 window.showModalDialog  突然要关闭窗体的时候捕获时间 在网上搜索资料 找到答案

 子窗体

<script language=javascript>

 window.onbeforeunload = function() {

var arrArgs = new Array('返回的值');

window.returnValue=arrArgs;

window.close();

}

</script>

 

父窗体

var result=window.showModalDialog(url,window,"DialogHeight=150px;dialogWidth:620px;status:no;scrollbars:auto;Resizable=no;");