日期:2014-05-17  浏览次数:20844 次

子窗口关闭,父窗口怎么刷新
在做一个项目,  
大概流程是 点了添加按钮以后,弹出一个窗口, 然后填入相关数据,点击确定 ,然后关闭该窗口 
回到刚才的列表页面 .
我想关闭子窗口的时候 ,在父窗口(列表页面)同时刷新显示出刚才添加的数据 . 不知道该怎么办了 .
在论坛找了好多资料 都不行..
部分代码:
子窗口的js
点击确定以后调用这个方法 ----
function tosave(){
var form = document.getElementById("form");
form.action = document.getElementById("_ContextPath").value + "/keep/BaoYang/save?";
form.submit();
window.close();
}
同时<body onUnload="javascrip:reshow();">
function reshow(){
window.opener.location.reload();
}


求达人解决 谢谢!

------解决方案--------------------
1、打开子窗口
2、在子窗口中对父窗口的变量进行复制
3、关闭子窗口


--这是父窗口中,点击“添加人员”弹出子窗口--
JScript code

<td class="tdConOne">
<input type="text" id="number" name="number" class="input" disabled="disabled" />
<font color="red"> *</font>
    &nbsp;&nbsp;
<input type="button" value="添加人员" class="button"  
onclick="openwin('*.do',700,550)"/>
</td>

//这个函数是打开一个新的窗口
function openwin(url,wwidth,wheight) 
 {
  var x=(screen.Width-wwidth)/2;
  var y=(screen.Height-wheight)/2;
  window.open(url, '', 'toolbars=0, scrollbars=0, location=0,
  statusbars=0, menubars=0, resizable=0, width='+wwidth+', 
  height='+wheight+', left='+x+', top='+y);
 }

------解决方案--------------------
2、在子窗口中对父窗口的变量进行赋值
------解决方案--------------------
$("#addForm").ajaxSubmit({
beforeSubmit:function () {
$("#saveBtn").attr("disabled",true);
}, 
success:function (data) {
if(data == "ok") {
alert("增加成功");
flushParentPage();
window.close();
}
if(data == "error") {
alert("增加失败");
}
$("#saveBtn").attr("disabled",false);
},
complete:function () {
$("#saveBtn").attr("disabled",false);
},
error : function() {
$("#saveBtn").attr("disabled",false);
alert("请求错误");
}
});
}


js里面写个这个,我也看不太懂 ,反正就这么写的
function flushParentPage() {
var pageNo = 1;
try {
pageNo = window.opener.document.getElementById("pageNo").value;
var url = window.opener.document.getElementById("url").value;
if(url.indexOf("?") != -1) {
url += "&pageNo=" + pageNo;
} else {
url += "?pageNo=" + pageNo;
}
window.opener.document.queryForm.setAttribute("action", url);
} catch (err) {

}
window.opener.document.queryForm.submit();
}

function closeOpenPage() {
window.close();
}
------解决方案--------------------
不是有parent吗
------解决方案--------------------
父窗口中的js片段
//xxAction是你要打开页面前的逻辑处理,再在action的配置文件中跳转到你要打开的jsp页面
open("xxAction","","menubar=no,toolbar=no,status=no,width=500,heigth=300");

在子窗口添加一个确定按钮触发一个事件,在js代码中最后加上下面代码
//opener表示的是父窗口
window.opener.document.getElementById("xxx").value = mgrno;
window.close();
------解决方案--------------------
上面的xxx是你父窗口中要赋的值。mgrno是子窗口选中的值。我忘记改过来了
------解决方案--------------------