【问题标题】:javascript parent and child windowjavascript父子窗口
【发布时间】:2011-01-06 22:10:56
【问题描述】:

我有一个使用 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();
}

【问题讨论】:

    标签: javascript parent-child


    【解决方案1】:

    回答您的问题:“这可能使用 javascript 吗?”

    是的

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

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

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

    【讨论】:

    • 我在我的问题中添加了代码,希望它有助于理解我的问题。
    • HTML 属于 .html 文件,CSS 属于 .css 文件,JavaScript 属于 .js 文件。最好不要用 JavaScript 填充 HTML。问题是当您从链接调用子窗口时,您丢失了对子窗口的引用。
    • 谢谢,你给我指了路,剩下的我想通了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多