Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Callback function call when child window is close

Tags:

javascript

I have open child window when click on button.In this window I have save some data into database. I want to call another java script function when child window is close.

I have already tried this Set a callback function to a new window in javascript solution but it is not working.

So please tell me how to call callback function ?

I have also set one hidden field from child window after successfully save.I have try to alert this hidden value but its alert before updating.

function open_child()
{
    $("#child_succ").val(0);
    alert($("#child_succ").val());
    window.open("child.php","Ratting","width=550,height=300,left=150,top=200,toolbar=1,status=1");
    alert($("child_succ").val());
}

Callback function

function test()
{
    alert("called from child window");
}
like image 767
Hkachhia Avatar asked Oct 31 '12 05:10

Hkachhia


People also ask

How do I listen to my child closing windows?

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.

When callback function is executed?

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action. The above example is a synchronous callback, as it is executed immediately.

Under what circumstances are callbacks useful?

Callbacks are generally used when the function needs to perform events before the callback is executed, or when the function does not (or cannot) have meaningful return values to act on, as is the case for Asynchronous JavaScript (based on timers) or XMLHttpRequest requests.

How do you call a callback function?

A custom callback function can be created by using the callback keyword as the last parameter. It can then be invoked by calling the callback() function at the end of the function. The typeof operator is optionally used to check if the argument passed is actually a function. console.


1 Answers

You may call a parent function from child window this way:

window.opener.your_function()

To call a child function in parent window:

var w = window.open(somelocation,''); //has a function on `window` called "test"
w.test();

If any of this tips help you, you may show us how the callback approach was used by you.

Hope this helps you.

Regards!

like image 150
felipeclopes Avatar answered Sep 18 '22 07:09

felipeclopes