Reputation: 5158
I need to show an alert in the parent window and then refresh it when closing the child window. I tried:
window.onunload = refreshParent;
function refreshParent() {
window.opener.focus();
window.opener.alert('Testing');
window.opener.location.reload();
}
This does show the alert in the parent, but I guess because the child is within the parent, the child window js freezes till I hit ok in the parent window. I can live with that, but the problem is, the parent window doesn't seem to get the focus when I show the alert, so the alert ends up being hidden behind the popup window. Any advice guys?
Upvotes: 0
Views: 9387
Reputation: 455
try this code
<!DOCTYPE html>
<html>
<head>
<script>
function openWin()
{
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>This is 'myWindow'</p>");
refreshParent();
}
function refreshParent() {
window.parent.focus();
window.parent.alert("message");
window.parent.location.reload();
}
</script>
</head>
<body>
<input type="button" value="Open 'myWindow'" onclick="openWin()" />
</body>
</html>
Upvotes: 2