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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.