John Doe
John Doe

Reputation: 2060

Refreshing Parent window after closing popup

I am creating a popup window that goes to hello.html. I want my original (parent page) to reload when i close the popup window (hello.html). I can't seem to get it to work, but I'm close. Here is the code I have so far for the main page and the hello.html page....

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function open_win()
{
window.open("hello.html","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
}
</script>


<script language="JavaScript">

function refreshParent() {
  window.opener.location.href = window.opener.location.href;

  if (window.opener.hello.html)

 {
    window.opener.hello.html.close()
  }
  window.close();
}
</script>


</head>

<body>

<script type="text/javascript">

var d=new Date();
document.write(d);

</script>

<form>
<input type="button" value="Open Window" onclick="open_win()">
</form>
</body>
</html>

Here is the hello.html...

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
</script>
</head>
<body>

Hello

</body>
</html>

Upvotes: 10

Views: 45096

Answers (7)

B.Nishan
B.Nishan

Reputation: 686

<script type="text/javascript">
    if ($("#<%=hfldClose.ClientID%>").val() === "Close") { // create hfldClose as hidden field and assign value by backend
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
        layerRefresh();
        window.parent.layerRefresh();
    }

    function layerRefresh() {
        window.parent.location.href = "your Routing url";
    }
</script>

Upvotes: 0

Zeke
Zeke

Reputation: 652

Put this script in the header of your popup window:

<script type='text/javascript'>
window.onunload = function(){
window.opener.location.reload();}
</script>

This will reload the parent window when you close the popup.

Upvotes: 0

ravi shankar
ravi shankar

Reputation: 11

This piece of code works as well if a new window is popped with the window.open feature.

setTimeout(function () { window.opener.location.reload(true); window.close();}, 3000);

Upvotes: 0

Vineesh K S
Vineesh K S

Reputation: 1964

Try putting this javascript code in your popup window:

window.onunload = function(){
  window.opener.location.reload();
};

/onunload event will trigger when you close your popup window, and window.opener.location.reload() will reload the source (parent) window./

Upvotes: 2

saun4frsh
saun4frsh

Reputation: 383

on click event of popup close function Try...

window.opener.location.reload(true);

Upvotes: 1

Stoia Alex
Stoia Alex

Reputation: 161

Do it like this, after creating the popup monitor its "closed" status property in an interval. But this is added in the parent document:

var pop = window.open("page.html", "popup",
            "width=800,height=500,scrollbars=0,title='popup'");
    pop.focus();

    var monitor = setInterval(function() {

        if (pop.closed) {
            document.location.reaload()
        }

    }, 1000);

Upvotes: 3

Split Your Infinity
Split Your Infinity

Reputation: 4229

Subscribe to the unload event in the child window and call the parent window from the child window to notify it is closing!

Edit Added a code sample...

function popupClosing() {
  alert('About to refresh');
  window.location.href = window.location.href;
}

var w = window.open("hello.html","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
w.onunload = function () {
  window.parent.popupClosing()
};

Upvotes: 12

Related Questions