开发者

Is it possible to call Javascript function in parent document from JS in iframe?

Both the iframe and the parent document are on the same domain. What I would like to do is giv开发者_开发技巧e the js running in the iframe a callback function that resides in the parent document. Is this possible?

      window.frames["testFrame"].org.myorg.events.onDataReady.addListener(function (e) {
                alert("Data ready!");
}

I would like "testFrame" to call the anonymous function. The above js would be in the parent document. Is this possible?

Thanks. Update

The following works:

$(document).read(function(){
   $(frameObj).load(function () {
                window.frames["testFrame"].org.myorg.events.onDataReady.addListener(function (e) {
                    var doc = $("#summaryFrame")[0].contentDocument;
                    doc.open();
                    doc.writeln(e.data.summaryHtml);
                    doc.close();
                });
});


Yes you can - I've done this many times before in a previous job (... their "software" was basically 1,000 frames and a tabbed document).

Assuming you have this code in your top frame:

function blah() { alert("it worked!"); }

You can call this in the iframe...

top.blah();

Also, you can have the parent call down into the child, but the other way around is easier in my opinion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜