14

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");
}
Community
  • 1
  • 1
Hkachhia
  • 4,463
  • 6
  • 41
  • 76

2 Answers2

21

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!

felipeclopes
  • 4,010
  • 2
  • 25
  • 35
-1

In the example you gave us the function is called on load event, so you have to change it with on close event:

// This function is defined in the child window
var RunCallbackFunction = function() { }; //reference holder only


// ---------------------------------------------------------------------------


// This code should appear in the parent window
//random function you want to call

function myFunc() { alert("I'm a function in the parent window"); }

//to actually open the window..
var win = window.open("window.html");
win.onclose = function() { win.RunCallbackFunction = myFunc; };
Mihai Matei
  • 24,166
  • 5
  • 32
  • 50