JS实现 子窗体关闭,父窗体刷新页面;

1.窗口关闭事件

javascript捕获窗口关闭事件有两种方法 onbeforeunload()  ,onUnload()

<body onUnload="myClose();">
function
myClose() { // 可能存在frame页面,所以要引用top窗口. var win = top.window; try { // 刷新. if (win.opener) win.opener.location.reload(); } catch (ex) { // 防止opener被关闭时代码异常。
 }
}

2.子父窗体间js调用

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

为易维护、易扩展、易复用、灵活多样而努力~~
原文地址:https://www.cnblogs.com/SpringDays/p/3129856.html