問:
我在做一套系統的時候碰到這樣一個問題。
彈出的模態窗口不能刷新父窗體。例如我新增數據是在模態窗口而添加成功了關閉后父窗體只能手動刷新。這樣就嚴重影響了一些效果。
我嘗試過一些方法但是始終不對。請各位高手進來一下。
用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()">