Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run function of parent window when child window closes?

I am calling the javascript window.open() function to load another url in a pop up. Once the users is finished it takes them to the last page that has a link that says close window that calls the window.close() function. Now when that page closes I need to update something in the original page that opened the window. Is there any way to do this? I have to call a function that is in my original page.

like image 360
ngreenwood6 Avatar asked Nov 22 '09 05:11

ngreenwood6


People also ask

How do you refresh the parent window in closing the child?

In the HTML markup of the Child page we need to place the JavaScript function RefreshParent which is called attached to the browser onbeforeunload event. Thus when the Child page popup window is closed the parent page is refreshed.

How do I transfer data from child window to parent window?

From a child window or a small window once opened, we can transfer any user entered value to main or parent window by using JavaScript. You can see the demo of this here. Here the parent window is known as opener. So the value we enter in a child window we can pass to main by using opener.

How do you find the parent element in a child window?

You just need to prefix “ window. opener. ” and write the same code that you will write in the parent window's HTML page to access its elements.

How do I know if my child window is closed?

If you store a reference to the child window when you call window. open() , then you can poll using setInterval() to see whether the window is still open using the window. closed property.


1 Answers

You can somehow try this:

Spawned window:

window.onunload = function (e) {     opener.somefunction(); //or     opener.document.getElementById('someid').innerHTML = 'update content of parent window'; }; 

Parent Window:

window.open('Spawn.htm',''); window.somefunction = function(){  } 

You should not do this on the parent, otherwise opener.somefunction() will not work, doing window.somefunction makes somefunction as public:

function somefunction(){  } 
like image 91
jerjer Avatar answered Sep 28 '22 03:09

jerjer