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.
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.
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.
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.
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.
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(){ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With