在A页面弹出一个模态窗口为B页面,当关闭B页面时自动刷新A页面。
A页面的JS:
function opens()
{
//打开模态窗口。
window.showModalDialog('yahoo.htm');
}
<input id="Button3" type="button" value="弹出B页面。" onclick="opens();"/>
B页面的JS:
<input id="Button1" type="button" value="关闭并刷新A页面。" onclick="javascript:window.opener.location.href='A.aspx';window.close();"/>运行:
在A页面点击“弹出B页面”,B页面弹出来了,之后点击B页面的“关闭并刷新A页面。”报出一下错误:
“window.opener.location为空或不是对象”
何解?
本人用window.open(B页面)运行可以,但是window.open(B页面)并不是模态窗口。
怎么解决?

解决方案 »

  1.   

    补充一下 这里还有涉及到页面传值的问题。
    A传值到B(已解决)
    B传值到A(???)
      

  2.   

    演示代码:
    父窗口: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    <script type="text/javascript">
    function openNewForm(){
    window.open("default7.aspx");
    }
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input id="Button1" type="button" value="button" onclick="openNewForm()" />
            <asp:TextBox ID="TextBox1" runat="server" TextMode="Password"></asp:TextBox></div>
        </form>
    </body>
    </html>
    了窗口:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
        <script type="text/javascript">
        function refreshPrtForm(){
            opener.location.reload();
        }
    function window.onbeforeunload() {
    refreshPrtForm();
    }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input id="Button1" type="button" value="button" onclick="refreshPrtForm()" />
        
        </div>
        </form>
    </body>
    </html>
      

  3.   

    A页面的JS: 
    function   opens() 

    //打开模态窗口。 
    window.showModalDialog('yahoo.htm'); 
    self.location.reload();

    <input   id="Button3"   type="button"   value="弹出B页面。"   onclick="opens();"/> 
    B页面的JS: 
    <input   id="Button1"   type="button"   value="关闭并刷新A页面。"   onclick="window.close();"/>呵呵 行的话别忘了结贴。
      

  4.   

    xiaoniao_28
    可以了,但是怎么从B传值到A》?
      

  5.   

    opener.location.reload();刷新父页面。
      

  6.   

    JS: A
    var a=window.showModalDialog('yahoo.htm');  
    if(a=="true")
    {
     //接下来的操作
    }
    else
    {
    //。
    }
    B:
     function  aa()
           {         
            if(window.confirm('test ..'))
            {
                window.returnValue="true";
            }
            else
            {
                window.returnValue="false";
            }        
            window.close();
           }
    <input id="Button1"  type="button"  value="关闭并刷新A页面。"  onclick="aa()"/> 
    不知道这样符合你的要求不?
      

  7.   

    function SelConvertArea()
        {
            var ReturnValue = window.showModalDialog("ShowForm/ShowArea.aspx?AreaID=" + AreaID + "&temp=" + Math.random(),null,"status=0;DialogWidth=500px;");
            if(ReturnValue == null || ReturnValue == undefined)
            {       
                    return false;
            }
            else
            {
                if(!(ReturnValue[0]=='') || !(ReturnValue[0]==','))
                {
                    var a =  ReturnValue[1] ;
                    var b = ReturnValue[0];
                }
                //if(result != null)
        location.reload();
            }
        }ShowArea.aspxprotected void btnSelect_Click(object sender, EventArgs e)
        {
            Response.Write("<script language=javascript>arrayObj = new Array(2);arrayObj[0]='" +
            OperateKey + "';arrayObj[1]='" +
            OperateValue + "';" +
            "window.close();returnValue=arrayObj;</script>");
        }
      

  8.   

    可以了,但是怎么从B传值到A》?
    ===========
    a页面
    var result = window.showModalDialog('yahoo.htm'); 
    b页面
    window.returnValue = "data";