1

Sorry to ask this again.

I am trying to reload the parent window after closing the son window. The code works fine in IE. but not in Chrome (Version 54.0.2840.99 m).

Is it my Chrome setting problem? Or the code problem?

I searched and tried all the solutions but it still not work. Please assist!! Thanks

<!-- Parent Window -->
<head>
<script language="javascript" type="text/javascript">
function popitup2(url) {
    newwindow=window.open(url,'email','top=200,left=500,height=500,width=600');
    if (window.focus) {newwindow.focus()}
    return false;
}


</script>



</head>
<body >
<A href='s.htm' onclick="return popitup2('s.htm')">Call S Method 1</a>
<BR><BR>
<a href="#" onClick="window.open('s.htm', '_blank')">Call S method 2/a>

<p id="demo"></p>

<script>
var d = new Date();
document.getElementById("demo").innerHTML = d;
</script>
</body>



<!--Son window (s.htm) -->

<head>
<script type="text/javascript">

window.onunload = unloadPage;

function unloadPage()
{

 window.opener.location.reload();
}
</script>
</head>

<body>
Son !!
</body>
</html>
  • Possible duplicate of [Javascript 'onunload' event not working in latest Version '54.0.2840.71 m' of Google Chrome browser](http://stackoverflow.com/questions/40280974/javascript-onunload-event-not-working-in-latest-version-54-0-2840-71-m-of-go) – Wiktor Zychla Nov 14 '16 at 07:54

1 Answers1

0

It's not the window.opener.location.reload() that doesn't work, but it's calling it from the onunload event. There are very strict rules as to what you are allowed to do in that event handler (to prevent spamming and such)

Check this plunker to see what I mean:

https://plnkr.co/edit/RGIrrupeqxd2bmc9M7ex?p=preview

In the example above you can reload the parent page from the child when clicking the link, but the exact same code doesn't work in the unload event.

Robba
  • 7,684
  • 12
  • 48
  • 76
  • There you have it, not sure if it's really a bug or working as intended though, but the result is the same, it doesn't work from an unload-handler. – Robba Nov 14 '16 at 08:34
  • thanks for your help first. But what should I do, if I need to reload the parent page unloadPage event? – user3317440 Nov 16 '16 at 02:08
  • The only things I can think of is either 1) Encourage people to close the popup through a button of your choosing and make that button refresh the parent before closing the popup, or 2) Use some tacky timeout script on the parent window to continuously check to see whether the child still exists (if that's even possible) – Robba Nov 16 '16 at 07:58