I am popping out a child window from parent window.Now, in child window, I have a html form that a user will fill and submit and request will go on server site.Now, I wanted response to this request redirected to parent window and my child window automatically closed out.Hope I am clear enough. If not let me know. thank you in advance.
I am popping out a child window from parent window.Now, in child window, I have a html form that a user will fill and submit and request will go on server site.Now, I wanted response to this request redirected to parent window and my child window automatically closed out.Hope I am clear enough. If not let me know. thank you in advance.
Share Improve this question asked Nov 7, 2011 at 4:47 pranay godhapranay godha 6552 gold badges7 silver badges13 bronze badges4 Answers
Reset to default 4If the pop-up window is created using window.open
, then the pop-up window can access the opening window using window.opener
.
On the main window, you have to create a function to receive data from the popup, something like this:
window.receiveDataFromPopup = function(data) {
// do things with data.
};
Then in the pop-up window, you can call that function on the opener like this:
window.opener.receiveDataFromPopup(data);
To close the window, just use
window.close();
Check jQuery Popup Window Return Value to Parent
basically the logic can be:
You response returns a page that contains a hidden-div that contains the message you want to display (hidden with CSS set
display:none;
)That child page returned also contains some JavaScript that fills in the parent window with the DIV content,
parent/* or opener */.document.getElementById(...).innerHTML = ...;
or calls a function on the parent to tell it it's now plete, likewindow.opener/*or parent*/.formIsComplete();
whereformIsComplete()
is a JavaScript function in the parent document/window.The last line of the JavaScript on the child window, will close itself, as simple as
window.close();
.
There is a way to access the parent window from the child. It is
window.opener //use window.opener to access the parent window.
So in the child window, once your form submission pletes, just call
window.opener.yourFunc() //Your func is a function on parent. Call this from the child.
Once this function is called close your child window using
window.close();
<script type='text/javascript'>
window.opener.location.reload();
window.close();
</script>