2

Both the iframe and the parent document are on the same domain. What I would like to do is give 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();
                });
});
3
  • Have you tried it? What happened? Commented May 14, 2011 at 23:04
  • David - actually I think it will work.. the problem is I am trying to run this code after the frame loads $("#myFrame").load() Commented May 14, 2011 at 23:07
  • "Yes". But generally not cross-site. Commented May 14, 2011 at 23:28

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Exaaaaactly :) (but if I said that you would have been mad at me)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.