Reputation: 3408
I used showModalDialog to open a Popup window from Javascript. I have this application is ASP.Net and I do post backs in the pop window.
window.showModalDialog('childpage.aspx', '', 'titlebar:no;status:no; help:no; center:yes; edge:raised;dialogWidth:950px;dialogHeight:950px;');
In the popup page, I added onunload event to refresh parent page whenever we close the popup.
<body onunload="window.opener.reload();">
I'm closing the window on a button click in Asp.net using below code:
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "var ua = window.navigator.userAgent; var msie = ua.indexOf(\"MSIE \"); if (msie > 0) { window.close(); } else { parent.document.getElementsByTagName('dialog')[0].close(); }", true);
It works fine in IE. In Chrome, I could close the window, but I am unable to refresh the page. Even closing popup in Chrome is not straight-forward. window.close doesn't work so I used a condition inside my script above to close the popup based on browser. Can anyone advise on how to refresh the parent page when browser is chrome? I have tried all the previous suggestions in this forum and other forums but no luck!!
I tried this too...
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "var ua = window.navigator.userAgent; var msie = ua.indexOf(\"MSIE \"); var isFirefox = typeof InstallTrigger !== 'undefined'; if (msie > 0 || isFirefox) { window.close(); } else { parent.document.getElementsByTagName('dialog')[0].close(); } window.opener.location.reload(true);", true);
Upvotes: 2
Views: 4079
Reputation: 1341
I had the same issue (Chrome 55.0.2883.87 Windows 10) in the end the only solution that worked was here: Refresh Parent page on close of pop up window. All credit to original answer but my version here for speed
var windowRef = window.open("http://www.google.de");
var monitor = setInterval(function () {
if (windowRef.closed) {
document.location.assign(getRefreshUrl(window.location));
clearInterval(monitor);
}
}, 100);
Super nasty to have a setInterval I know, but the only way it would work for me in Chrome.
Upvotes: 1
Reputation: 17
@user2169261
I had a similar problem with chrome. the parent window in firefox and IE could refresh correctly but not in chrome. below is the code that I used to get it to work:
Parent window code (file name: test.php)
<html>
<head>
<title>Parent window</title>
</head>
<body>
<h2>This is the Parent window.</h2>
<a href="javascript:void(0);" NAME="" title=""
onClick=window.open("test2.php","Ratting","width=550,height=170,0,status=0,top=200,");>
Click here to open the child window</a>
</body>
</html>
Child window code (file name: test2.php)
<html>
<head>
<title>Child Window</title>
<script type="text/javascript">
function refreshAndClose()
{
window.close();
if (window.opener && !window.opener.closed)
{
window.opener.location.reload();
}
}
</script>
</head>
<body>
<h2>Click the button below to close this window and refresh the parent window</h2>
<input type="button" value="submit" onclick="return refreshAndClose()"/>
</body>
</html>
This might not be exactly what you are looking for but I hope it helps.
Upvotes: 2