8

window.parent.functionname();子ページのように親関数を呼び出しています。window.child.function()親ページから子ページにを呼び出すにはどうすればよいですか。

どんな助けでも大歓迎です。

4

4 に答える 4

11

iFrame に ID を付けて試してください

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

これは、順序に関係なく、同じページに複数の iFrame がある場合でも機能します。

于 2012-12-19T13:29:24.927 に答える
4

iframeはありますか?

そのようなことをしてください:

window.frames[0].contentDocument.functionname();
于 2012-12-19T13:22:32.980 に答える
3

親ページ

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()');
}​
于 2012-12-19T13:30:27.127 に答える