Refresh Parent page when Child window closes

The code sample contains code for two HTML pages - parent and child. We aim to call a child page from the parent by using Javascript functions and refresh the parent page when the child window is closed.

The code for refreshing is contained in the child page.

Code for the parent page Main.html is next:



<html>
<head>
<title>Main Window</title>
<script Language = "JavaScript">
function OpenWin()
{
window.open("Child.html", "Child",'width=300,height=200,left=150,top=100,scrollbar=no,resize=no');

}
</script>
</head>
<body>
<h4>Click the button to open a new window.</h4>
<input type="button" value="Click Me" onclick="OpenWin();"></br>

</body>
</html>




Save the followin code as Child.html



<head>
<title>Child Window</title>
<script Language = "JavaScript">
function CloseWin()
{
window.close();
opener.location.reload();
}
</script>
</head>
<body>
<h4>Click the button to close the window.</h4>
<input type="button" value="Click Me" onclick="CloseWin();">
</body>
</html>


Comments

Author: Shankar17 Jul 2008 Member Level: Gold   Points : 1

Hi

You can also use "window.opener" for accessing the parent page.

Thanks
A S



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: