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

来源:百度文库 编辑:神马文学网 时间:2024/04/27 15:25:32

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()