Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to refresh the page when i close the popup window..?


see my code
-------------

<a href="#" onclick="window.close();" class="Content">Close Window</a>

I want, when i close the popup window, immediately the parent form should get refresh or reload..

How to do this...?
Posted
Updated 28-Jul-11 4:04am
v3

There are several ways but one simple way could be
JavaScript
function closeandrefresh(){
  opener.location.href = opener.location.href;
  window.close(); 
}


And update your link as

<a href="#" onclick="closeandrefresh();" class="Content">Close Window</a>
 
Share this answer
 
Comments
Ed Nutting 28-Jul-11 10:26am    
Good answer, much simpler than mine. I hadn't thought about using the opener variable. Would suggest you tell the user how to attach this method to the closed event as most user's prefer to click the red X button on popup windows rather than Close links. I would also question how reliable this is in all browsers though? Namely IE never seems to conform. Would advise OP to check all javascript (inc. this) for cross-browser compatibility and also say that Chrome and Firefox are best to develop on as they are the most standards compliant. My 5+, Ed :)
Dear it is possible through AJAX............
 
Share this answer
 
Comments
gani7787 28-Jul-11 9:29am    
Can you tell me the steps...?
You can use a recursive function in the parent window to wait for the popup to close. E.g.

HTML
<html>
<head>
<script type="text/javascript">

JavaScript
var generator = null;
function show_prompt()
{
    //Open a popup and store the handler in a var named generator
    generator = window.open("", "New Popup", "width=400, height=400");
    //Add some html to the new window
    generator.document.write("<html><head><title>Test</title></head><body>");
    generator.document.write("<p><a href=\"javascript:self.close()\"> Close</a></p>");
    generator.document.write("</body></html>");
    generator.document.close();
    generator.focus();
    
    //The crucial line! Start the recursive function that will poll the new popup window until it's closed. 
    WaitForClose();
}
function WaitForClose()
{
    //Check to see if the popup has been closed
    if(!generator.closed)
    {
        //If not, recall this function - the recursion
        setTimeout("WaitForClose()", 500);
    }
    else
    {
        //If popup has been closed, call the PopupClosed funtion
        PopupClosed();
    }
}
function PopupClosed()
{
    //Do something here!
    alert("x");
}

HTML
</script>
</head>
<body>
<input type="button" onclick="show_prompt()" value="Show prompt box" />
</body>
</html>


Hope this helps,

Ed :)
 
Share this answer
 
JavaScript
function refreshParent() {
  window.opener.location.href = window.opener.location.href;
  if (window.opener.progressWindow)
 {
    window.opener.progressWindow.close()
  }
  window.close();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900