我正在window.parent.functionname();从子页面调用父函数。如何window.child.function()从父页面调用子页面。
任何帮助表示赞赏。
我正在window.parent.functionname();从子页面调用父函数。如何window.child.function()从父页面调用子页面。
任何帮助表示赞赏。
给你的 iFrame 一个 id 并尝试
document.getElementById("iFrameId").contentWindow.functionname()
即使您在同一页面中有多个 iFrame,无论它们的顺序如何,这也有效。
你有 iframe 吗?
做这样的事情:
window.frames[0].contentDocument.functionname();
    父页面
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 win = null;
function openAndCall(id){
    if (win!=null && win.closed==false){
        win.close();
    }
    win = window.open("/somePage");
    win.onload = function(){
        win.callSome(id);
    };
}