`
nbkangta
  • 浏览: 423110 次
  • 性别: Icon_minigender_1
  • 来自: 宁波
社区版块
存档分类
最新评论

关于模态弹出窗口刷新父窗体

阅读更多

一个关于模态弹出窗口刷新父窗体的问题。
问:
我在做一套系统的时候碰到这样一个问题。
弹出的模态窗口不能刷新父窗体。例如我新增数据是在模态窗口而添加成功了关闭后父窗体只能手动刷新。这样就严重影响了一些效果。
我尝试过一些方法但是始终不对。请各位高手进来一下。
用OPEN打开的不管是在关闭窗体时自动刷新都没有任何问题。见下例
父窗体代码
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title></title>
</head>
<body>
<a href="javascript:void(0)" onclick="window.open('2.html','','')">open</a>
</body>
</html>
子窗体代码
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title></title>
</head>
<body onUnload="opener.location.reload()">
<!-
用按纽直接刷新父窗体
<a href="javascript:opener.location.reload()">刷新</a>
->
</body>
</html>
 
换做模态后的程序。
父窗体代码
<%@ page contentType="text/html; charset=GBK" %><HEAD>
<body onUnload="opener.location.reload()">
<script language="JavaScript">
function showabout()
{
  var returnValue=showModalDialog('2.html','','dialogWidth:520px;dialogHeight:510px;help:no;center:yes;resizable:no;status:no;scroll:no');

void(0);
</script>
<a href="javascript:void(0)" onClick="showabout()">open</a>
子窗体代码
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title></title>
</head>
<body onUnload="opener.location.reload()">
<a href="javascript:opener.location.reload()">刷新</a>
</body>
</html>
 
请各位参考一下上面的代码,我感觉错误好象是出在
opener.location.reload()
谢谢
______________________________________________________________________________________________
答1:
模态窗口不能在子窗口中直接刷新父窗口
父窗体代码
<%@ page contentType="text/html; charset=GBK" %><HEAD>
<body onUnload="opener.location.reload()">
<script language="JavaScript">
function showabout()
{
  var returnValue=showModalDialog('2.html','','dialogWidth:520px;dialogHeight:510px;help:no;center:yes;resizable:no;status:no;scroll:no');
  location.reload()//模态窗口传值下来后就可以刷新了.

void(0);
</script>
<a href="javascript:void(0)" onClick="showabout()">open</a>
子窗体代码
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title></title>
</head>
<body onUnload="opener.location.reload()">
<a href="javascript:opener.location.reload()">刷新</a>//???在子窗口中不能刷新父窗口,只有window.close下去后才可刷新.
</body>
</html>
______________________________________________________________________________________________
答2:
模态对话框是不能用opener引用父窗口的,而是需要父窗口主动传递指针变量的
这个window.showModalDialog有第二个参数,就是做这个用的,你需要把window穿过去,就是这样
var returnValue=showModalDialog('2.html',window,'dialogWidth:520px;dialogHeight:510px;help:no;center:yes;resizable:no;status:no;scroll:no');
这样在对话框中就可以引用父窗口对象,怎么引用呢,通过window.dialogArgument就可以应用父窗口了。
______________________________________________________________________________________________
答3:
谢谢。我终于搞定了。
上面的dialogArgument差个S
我调了半天。发现在body里面应该加上location
也就是<body onUnload="window.dialogArguments.location.reload()">

 

摘自以下地址: http://www.blogjava.net/ljy032/

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics