Home > Code > Javascript > How to refresh parent page after closing popup window using JavaScript?

How to refresh parent page after closing popup window using JavaScript?

by Thamil   on Sep 11, 2014   Category: Javascript   |  Views: 12532    |  Points: 25   |  Gold 


Below is the sample code to refresh the parent page on closing of child/popup windows using JavaScript code.

Parent page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="test.WebForm5" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Parent Window</title>

<script type="text/javascript" language="javascript">
var ChdWind;
function ShowChild() {
ChdWind = window.open("Child.aspx", "Popup", "toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=0,width=200,height=200,left = 600,top = 300");
ChdWind.focus();
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div><u>Parent Page</u></div><br /><br />
<asp:Button ID="Button1" runat="server" OnClientClick="ShowChild();" Text="Button" /><br /><br />
<div>PPage refreshed at: <%=DateTime.Now %></div>
</form>
</body>
</html>


Child/Popup Window:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Child.aspx.cs" Inherits="test.Child" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Child Window</title>
<script type="text/javascript" language="javascript">
function refreshParentPage()
{
window.opener.location.href = window.opener.location.href;
if (window.opener.progressWindow)
{
window.opener.progressWindow.close();
}
window.close();
}
</script>
</head>
<body onunload="refreshParentPage()">
<form id="form1" runat="server">
<div>
Child Window
</div>
</form>
</body>
</html>




Post Code  |  Code Snippet Home

User Responses


  Re :How to refresh parent page after closing popup window using JavaScript?   
Posted by Celv
on 31/10/2014
Points : 5

nice article but u have to show the demo TJ

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts