如何在javascript中调用窗口子函数?

如何在javascript中调用窗口子函数?,javascript,frames,Javascript,Frames,我正在调用父函数,如window.parent.functionname()从子页面。如何从父页面到子页面调用window.child.function() 感谢您的帮助 您有iframe吗 这样做: window.frames[0].contentDocument.functionname(); 给你的iFrame一个id,然后再试一次 document.getElementById("iFrameId").contentWindow.functionname() 即使在同一页面中有多个i

我正在调用父函数,如
window.parent.functionname()从子页面。如何从父页面到子页面调用
window.child.function()

感谢您的帮助

您有iframe吗

这样做:

window.frames[0].contentDocument.functionname();

给你的iFrame一个id,然后再试一次

document.getElementById("iFrameId").contentWindow.functionname()

即使在同一页面中有多个iframe,无论它们的顺序如何,这种方法也能起作用。

父页面

var windowRef = null;

function openChildWindow() {
    if ((windowRef != null) && (windowRef.closed == false)) {
        if (windowRef.closed == false) windowRef.close();
        windowRef = null;
    }

    var windowUrl = 'ChildPage.aspx';
    var windowId = 'NewWindow_' + new Date().getTime();
    var windowFeatures = 'channelmode=no,directories=no,fullscreen=no,' + 'location=no,dependent=yes,menubar=no,resizable=no,scrollbars=yes,' + 'status=no,toolbar=no,titlebar=no,' + 'left=0,top=0,width=400px,height=200px';

    windowRef = window.open(windowUrl, windowId, windowFeatures);

    windowRef.focus();

    // Need to call on a delay to allow
    // the child window to fully load...
    window.setTimeout(callChildWindowFunction(), 1000);
}

function callChildWindowFunction() {
    if ((windowRef != null) && (windowRef.closed == false)) windowRef.childWindowFunction();
}​
function childWindowFunction() {
    alert('Hello from childWindowFunction()');
}​
子页面

var windowRef = null;

function openChildWindow() {
    if ((windowRef != null) && (windowRef.closed == false)) {
        if (windowRef.closed == false) windowRef.close();
        windowRef = null;
    }

    var windowUrl = 'ChildPage.aspx';
    var windowId = 'NewWindow_' + new Date().getTime();
    var windowFeatures = 'channelmode=no,directories=no,fullscreen=no,' + 'location=no,dependent=yes,menubar=no,resizable=no,scrollbars=yes,' + 'status=no,toolbar=no,titlebar=no,' + 'left=0,top=0,width=400px,height=200px';

    windowRef = window.open(windowUrl, windowId, windowFeatures);

    windowRef.focus();

    // Need to call on a delay to allow
    // the child window to fully load...
    window.setTimeout(callChildWindowFunction(), 1000);
}

function callChildWindowFunction() {
    if ((windowRef != null) && (windowRef.closed == false)) windowRef.childWindowFunction();
}​
function childWindowFunction() {
    alert('Hello from childWindowFunction()');
}​

我猜您所说的是在当前文档的iFrame中调用函数。如果是,请将其添加到您的问题中。不,我没有任何iframe如果您使用的是
窗口。父项
并且它工作正常,那么您就有一个iframe。它将位于选项卡条中。我正在使用dhtmlx tabstrip加载子页面。一些代码:
tabbar.setHrefMode(“iFramesonDemand”);tabbar.setContentHref(“a1”,“../../MailContactMain/Index”)然后我可以使用a1 idI调用我没有任何帧。那我怎么办that@Naidu你的孩子在哪里或什么地方?当您创建window.parent时,您是在哪个上下文中创建的?给我更多的密码?!我正在使用dhtmlx选项卡栏来显示子对象。代码:
tabbar.setHrefMode(“iframes on demand”);tabbar.setContentHref(“a1”,“../../MailContactMain/Index”)那么我将使用a1作为iframeOh,我以前从未使用过。但必须有一个iframe或frame。如果没有框架,则属性window.parent是相同的链接just window(window.parent==window)=>true如果您在框架中,则window.parent是框架持有者文档。如果您在框架持有者文档中,请使用window.frames[0]或window.frames[1]在框架上下文中切换。看这里: