【问题标题】:How to reload parent page on closing PopUp window?如何在关闭弹出窗口时重新加载父页面?
【发布时间】:2013-09-15 04:58:03
【问题描述】:

我在母版页上有一个链接按钮“条款和条件”。当使用点击它时,使用此代码会显示一个弹出窗口

Dim myScript As String

            myScript = "<script>window.open('Terms.aspx?',null,'height=750, width=1024,status= no,resizable= no, scrollbars=yes,toolbar=no,location=no,menubar=no'); </script>"

            ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "pop", myScript, False)

我在弹出窗口页面上有一个接受按钮,我正在关闭这个弹出窗口

ClientScript.RegisterStartupScript(GetType(Page), "closePage", "window.close();", True)

问题是我想在此弹出窗口关闭后刷新父窗口。我怎样才能做到这一点? 这不起作用Refreshing Parent window after closing popup

更新

<div style="padding:5px 0;">
      <asp:Button ID="btnAccept" runat="server" Text="Accept"  OnClientClick="Refresh()" style="HEIGHT: 19px;background: #C0003B;color: white; " /> &nbsp;<asp:Button ID="btnReject" runat="server" Text="Reject" OnClientClick="Refresh()" style="HEIGHT: 19px;background: #C0003B;color: white;"/>

</div>

   function Refresh() {
       return confirm('Are you sure?');
       window.onunload = refreshParent;
       function refreshParent() {
           window.opener.location.reload();
       } 
   }

【问题讨论】:

    标签: c# javascript asp.net vb.net


    【解决方案1】:

    您可以使用'window.opener'访问父窗口,因此,在子窗口中编写如下内容:

    onunload="window.opener.location.reload();"
    

    或者使用这个

    <script>
        window.onunload = refreshParent;
        function refreshParent() {
        var retVal = confirm("Are you sure ?");
               if( retVal == true ){
                window.opener.location.reload();
              else
                return false;
    
        }
    </script>
    

    【讨论】:

    • 我的朋友,您的解决方案非常有效,非常感谢您。顺便说一句,是否可以添加确认对话框? return confirm('Are you sure?'); 之类的东西我尝试包含它,我得到了对话框,但是父页面没有刷新。
    • 请在您的问题中添加代码,以便我可以看到您在以错误的方式或遗漏的方式做的事情。
    • 它不起作用.. 我没有看到任何对话框,也没有刷新父页面。
    • nope 仍然无法正常工作..您在答案中更新的那个既没有显示对话框也没有刷新页面..但是我在问题中发布的 javascript 显示了对话框但没有无论我点击“是”或“否”或“x”(关闭)......结果都是一样的。 IE。父级没有刷新,后面的代码正在执行。
    猜你喜欢
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-19
    • 1970-01-01
    • 2012-06-03
    相关资源
    最近更新 更多