简体   繁体   English

关闭弹出窗口后刷新父页面

[英]Refresh the parent page after closing a pop up window

I have aspx page that has a gridview in which there is an update button. 我有aspx页面具有gridview,其中有一个更新按钮。 when I click update button a pop up window opens. 当我单击更新按钮时,将弹出一个窗口。 The second aspx page (pop up windows) has fields a delete button. 第二个aspx页(弹出窗口)具有删除按钮字段。 when I click the delete button the second aspx page close and the row is deleted from the gridview in the first aspx page. 当我单击删除按钮时,第二个aspx页面关闭,并且该行从第一个aspx页面的gridview中删除。 I'm not able to see the row has been deleted from the gridview until i refresh manually the page. 在手动刷新页面之前,我无法看到该行已从gridview中删除。

How can I refresh the parent page(the page that has the gridview) right after closing the second page (the pop up window page)?? 关闭第二个页面(弹出窗口页面)后,如何立即刷新父页面(具有Gridview的页面)? I tried this but didn't work : 我尝试了这个但是没用:

Response.Write("<script>window.close();</" + "script>");
Response.Write("<script>window.opener.location.reload();</" + "script>");

You can use window.opener in the pop up window, just add 您可以在弹出窗口中使用window.opener ,只需添加

window.opener.location.reload();

in pop up window on onbeforeunload or onunload event. onbeforeunloadonunload事件的弹出窗口中。 but that won't work on chrome, it works on firefox. 但这不适用于Chrome,但适用于Firefox。

Another work around you can use setInterval to check if pop up window is closed or not in the main page: 您可以使用setInterval来检查弹出式窗口是否在主页中关闭:

var page = null;
function openPopUp() { 
    page = window.open("desiredPage.html","windowName", "width=200,height=200"); 
    setInterval(function() {
        if(page != null && page.closed) {
            window.location.reload();
        }
    }, 1000);
}

Second solution works on all browsers. 第二种解决方案适用于所有浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM