javascript父子窗口

时间:2011-01-06 22:10:57

标签: javascript parent-child

我有一个使用javascript的页面,并打开一个子窗口,用于更新父窗口中的某些字段。

现在更新的字段有onchange()函数我希望子窗口在更新字段时调用此函数。

这可以使用javascript吗?

修改

我的代码:

这是打开子窗口的链接:

<a href="javascript:void(0);" style="width:100%; height:125%" onclick="window.open('otherExpenses.php','Ratting','width=350,height=550,left=50,top=50,toolbar=1,status=1,');">Open Child</a>

在子窗口中,一些操作是通过用户交互完成的,这就是孩子关闭的方式:

<a href="javascript:void(0);" onclick="post_value()">Close Child</a>

post_value()函数:

function post_value()
{
    opener.document.overHeads.overheadOther.value = document.otherExpenses.TextBox27.value;
    opener.document.overHeads.hiddenOther.value = document.otherExpenses.TextBox27.value;
    //here I want to call a function from the parent window that updates some field in the parent window.
    self.close();
}

1 个答案:

答案 0 :(得分:1)

回答你的问题:“这是否可以使用javascript?”

如果您想要更好的答案,则需要发布更多代码。

如果该函数属于父窗口,则必须从父窗口的上下文将其附加到子窗口:

//w is the child window
w.document.getElementById('theId').onchange(window.somefunction);
相关问题