Reputation: 65
How to refresh the parent page and closing the child window using javascript when I click the button in parent page asp.net I am able to refresh the parent page but my child window is not closing. My C# Code is
string script = @"<script>
function RefreshParent()
{
window.close();
window.opener.location.reload();
}RefreshParent();
</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "ssr", script);
Upvotes: 3
Views: 7608
Reputation: 176886
just try this code in your child window
Page.ClientScript.RegisterStartUpScript(this.GetType(),
"close",
"<script language=javascript>window.opener.location.reload(true);
self.close();</script>");
Upvotes: 1
Reputation: 4617
You are closing your child window before your parent window gets refreshed. Try it this way
<string script = @"<script>
function RefreshParent()
{
window.opener.location.reload();
window.close();
}RefreshParent();
</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "ssr", script);
Upvotes: 0
Reputation: 5083
Example with a link:
<script language="Javascript">
<!-- Start
document.write('<a href="javascript:self.close()" onClick="opener.location.reload(true);">Close</a>');
// Stop -->
</script>
Upvotes: 0