0

のような iFrame を作成します。

var iframe = dojo.io.iframe.create(generatedRequestId);

次のような追加の JavaScript 関数を挿入したいと考えています。

関数 printThis() { window.print(); }

親ウィンドウで次のようなコードから printThis() 関数を呼び出すことができるように、iFrame で

_setPrintExportCookieInterval: function(/**String*/requestId, /**function*/closePopup, /**String*/exportTypeId) {
    //have the interval autoexpire after some amount of seconds
    var count = 0;
    var intervalMs = 2000;

    var intervalId = self.setInterval(function() {
        var reportCookie = dojo.cookie(requestId);
        if(reportCookie || count > 300000) { //5 mins
            //if there's a status failure, don't close the window
            if(reportCookie == "success") {
                //console.debug(exportTypeId);
                if(exportTypeId == PRINT) {
                    var iframe = dojo.byId(requestId);
                    iframe.printThis();
                }
                closePopup();
            } else {
                console.debug("print/export request returned with nonstandard status " + reportCookie);
            }
            window.clearInterval(intervalId);
            //delete the cookie
            dojo.cookie(requestId, null, {path: "/", expires: -1});
            //destroy the iframe
            //dojo.destroy(dojo.byId(requestId));
        };
        count+=intervalMs;
    }, intervalMs);

    return intervalId;
},

-これは可能ですか?dojo.io.iframe.create(generatedRequestId) は、onLoad で実行されるコードである 2 番目のパラメーターを取ることを知っていますが、iframe の読み込み後に呼び出すことができる関数である必要はありませんか?

アドバイスをありがとう。

4

1 に答える 1

1

ブラウザー JavaScript で「グローバル」変数または関数を宣言すると、変数はwindowオブジェクトのプロパティとして使用できます。iframe が同じオリジンからのものである場合、iframewindowの contentWindow プロパティを介してそのオブジェクトにアクセスできます。

iframe.contentWindow.printThis();
于 2012-11-11T14:07:07.793 に答える