Refresh parent window from a pop-up

June 28, 2004 · 6 Comment s

It's amazing how many times I've had to use this simple little function in projects throughout the years. You've got a link that opens a pop up window whereupon you do something that updates your database. What you also need is for the pop up window to close and the parent window to refresh to reflect the database change.
/*
   Reloads the parent window
*/
function parentReload() {
   if (window.opener && !window.opener.closed) {
      window.opener.location.reload();
      self.close();
   }
}
The if statement is basically checking that the window that fired up the popup window is still available.

Tags: JavaScript

6 response s so far ↓

  • 1 shola // May 28, 2007 at 9:25 AM

    Good script nice one
  • 2 tosin // May 28, 2007 at 9:42 AM

    where would i put the script?
  • 3 dsa // Jun 27, 2007 at 9:26 AM

    where do i've to include the script.?
  • 4 derya // Sep 17, 2007 at 5:58 PM

    try <body onunload="parentReload();">
  • 5 mike // Jan 10, 2008 at 7:52 PM

    some versions of IE won't do this correctly:
    window.opener.location.reload();

    my fix was:
    window.opener.location.href = some_url;
  • 6 Mika // Feb 1, 2008 at 12:29 PM

    Nice script! Thanks a lot mate!

Leave a Comment

Leave this field empty: