Jump to content

how to close popup and refresh the parent window.


garrisonian14

Recommended Posts

Hi,

 

I am using php.When user clicks on a particular link a pop up window is opened (using javascript window.open method).

In this window there is a form . on submiting this form we make entries in db. On success of entries i need to close this pop up and refresh the parent window.

I close the pop up using javascript window.close function. but don't know how to refresh the parent window.

In general, you refresh the original window by:

 

  opener.location = opener.location;

 

most times when I've needed to do this I've ended up creating a hidden form in the opener and then have the child window copy values to it before submitting and closing itself, e.g. main window:

 

  <form method=post name=HiddenForm>

    <input type=hidden name=val1 />

  </form>

 

child window, script section:

 

  var submit_close = function() {

    // copy value(s)

    opener.document.HiddenForm.val1.value = document.VisibleForm.txtfield.value;

    opener.document.HiddenForm.submit();  // submit main window form

    window.close(); // close child window

    return false;

  }

 

child window html:

 

  <form name=VisibleForm>

    <input type=text name=txtfield />

    <button type=submit onclick="submit_close()">Submit</button>

  </form>

 

It's a little more complex, but it solves the race condition where the reload of the main page finishes before the submit of the child window (and it looks like nothing happened).

 

-- bjorn

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.