Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh Parent page on close of pop up window

I have a Parent page in which, I have added a search functionality.

like below

function FunClick(StrPriCaption) {
        var StrPriHTML = "";
        if (StrPriCaption == 'AdvSearch') {
            //document.getElementById('TxtCondition').value = "AdvSearch";
            //form1.submit();
            var StrPriReturnValue = "";
            window.open('FrmInwardHdrAdvanceSearch.aspx', null, 'height=370,width=630,top=0,left=0,resizable=yes,scrollbars=yes');

        }
 }

And it works perfectly. It opens a pop up window page for me to search for.

But now what I want is, IF I close the pop up,I want to refresh the parent page.

I tried with below code in Child page, but it didn't refreshed the parent page.

 function CloseWindow() {
    window.close();
    window.opener.location.reload();
 }

How can I do this using Javascript?

like image 267
Nad Avatar asked Aug 12 '16 11:08

Nad


1 Answers

Method 1

<script>
function popup() {
    var win = window.open("", "Page Title", "toolbar=no, location=no");
    win.document.body.innerHTML = '<a href="#" onclick="window.opener.location.reload();window.close();">Close Me</a>';
}
</script>
<a href="#" onclick="popup()">Open Me</a>

It creates a popup with a link to close the window and refresh parent.

Demo: https://jsfiddle.net/eke4f72r/

Method 2

<script>
function popup() {
    var win = window.open("", "Page Title", "toolbar=no, location=no");
    var win_timer = setInterval(function() {   
      if(win.closed) {
          window.location.reload();
          clearInterval(win_timer);
      } 
      }, 100); 
}
</script>
<a href="#" onclick="popup()">Open Me</a>

It detects from the parent window if child is closed. If true, it reloads the page.

Demo: https://jsfiddle.net/gv6nmdn9/

EDIT When using method 1, make your parent to open the popup you want and just add this in your child:

<a href="#" onclick="window.opener.location.reload();window.close();">Close Me</a>
like image 154
NETCreator Hosting - WebDesign Avatar answered Oct 18 '22 22:10

NETCreator Hosting - WebDesign