Return to parent window using javascript

I pull the child window out of the parent window. Now, in the child window, I have an html form that the user will fill out and submit and request to go to the server site. Now I wanted the response to this request to be redirected to the parent window and my child window will automatically close. I hope I'm clear enough. If not let me know. thank you in advance.

+4
source share
4 answers

Mark jQuery popup Return value for parent

basically the logic could be:

  • The response returns a page containing a hidden-div containing the message you want to display (hidden with a set of CSS display:none; )

  • This child page also contains JavaScript that populates the parent window with the contents of the DIV, parent/* or opener */.document.getElementById(...).innerHTML = ...;
    or calls a parent function to tell it that it has completed, for example window.opener/*or parent*/.formIsComplete(); where formIsComplete() is the JavaScript function in the parent document / window.

  • The last line of JavaScript in the child window will be closed by itself, as simple as window.close(); .

+2
source

If a popup is created using window.open , then a popup can open an open window using window.opener .

In the main window, you should create a function to receive data from a popup window, something like this:

 window.receiveDataFromPopup = function(data) { // do things with data. }; 

Then in the popup you can call this function on the opener as follows:

 window.opener.receiveDataFromPopup(data); 

To close the window, simply use

 window.close(); 
+3
source

There is a way to access the parent window from a child.

 window.opener //use window.opener to access the parent window. 

So, in the child window, as soon as your form is completed, just call

 window.opener.yourFunc() //Your func is a function on parent. Call this from the child. 

Once this function is called, close the child window using

 window.close(); 
0
source
 <script type='text/javascript'> window.opener.location.reload(); window.close(); </script> 
0
source

Source: https://habr.com/ru/post/1379939/


All Articles