最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

return back to parent window using javascript - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a ment  | 

4 Answers 4

Reset to default 4

If 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:

  1. You response returns a page that contains a hidden-div that contains the message you want to display (hidden with CSS set display:none;)

  2. 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, like window.opener/*or parent*/.formIsComplete(); where formIsComplete() is a JavaScript function in the parent document/window.

  3. 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>
发布评论

评论列表(0)

  1. 暂无评论