父窗口
<html> 
<head>   
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>子窗口</title>   
<script language="javascript">   
  
</script>   
</head>     
<body> 
<input type="button" name=showdiv value="showModalDialog打开窗口"onClick=" window.showModalDialog('test.html'); window.location.reload();"> 
 </body>   
</html> 
子窗口
<script language="javascript"> 
function test(){
        alert('成功!');   
        window.opener.location.href=window.opener.location.href;    
        window.close();  
}</script> 
<input name=Button type=button value=关闭并刷新父页面 onClick="test()">
alert('成功!');   
window.opener.location.href=window.opener.location.href;    
window.close(); 
这三句是在网上查到的,说是就是解决window.showDialog弹出窗口关闭并刷新父窗口,但我在用时出报错:
window.opener.location 为空或不是对象 

解决方案 »

  1.   

    这可不是指的是showDialog窗口,这个是window.open()窗口的刷新方法
    showDialog直接关闭,不用其他的控制
    父窗口 window.showModalDialog('test.html'); 
    window.location.reload();
    其实已经做了刷新
    后一句是在子窗口关闭后才执行的
      

  2.   

    子窗口中
    function test(){ 
    window.returnValue = "返回值";
    window.close();  
    } 在父窗口中
    var ret = window.showModalDialog('test.html');//在子窗口关闭的时候,可以获得子窗口的返回值
      

  3.   

    谢谢lihui_shine
    我明白你的意思了,在关闭子的时候回自动去刷父,这是因为在父里写了"window.location.reload();",现在因为我的父是封装好的,我没办法去里面写上这句话,那这时我要怎么来实现弹出窗口关闭并刷新父窗口
      

  4.   

    // 打开模式窗口
    function openNewWin(){
        window.showModalDialog("test.html",{win:window},'dialogHeight:200px;dialogWidth:200px');
    }//模式窗口的方法
    function closeMe(){
        window.dialogArguments.win.location.reload();
        window.close();
    }楼主你试下!
      

  5.   

    模态对话框是不能用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.dialogArguments就可以应用父窗口了。 
    在body里面加上location <body onUnload="window.dialogArguments.location.reload()">