Reputation: 2661
I am not sure if this is possible but I have a small web application that is responsible for uploading files to the server. This app is used by another app which includes it in an iFrame.
The uploader app is using jQuery form to submit the file in the background and I would like to be able to notify the parent app when the upload is complete and the success callback fires.
I was thinking about somehow passing a function into the iFrame app that could be called from the parent but I am not sure how to do this or if it is even possible.
Upvotes: 0
Views: 3149
Reputation: 4179
You can call parent.functionname. Or you can try the IFrame event, onLoad to call from the parent page itself.
Upvotes: 1
Reputation: 91617
If both apps are hosted on the same domain, accomplishing this is trivial.
To call a function in the parent window from the iframe:
parent.myFunction();
To call a function in the iframe from the parent window:
document.myFrameName.myFunction();
(This requires that the iframe have a name
attribute set).
If the apps are on different domains, you'll have to perform some greater hackery to accomplish this.
Upvotes: 1
Reputation: 4299
I'm not sure what's the right way to do this, but you can write something like document.callback = function() { ... }
in your parent frame and parent.document.callback()
in your iframe.
Of course your pages in parent frame/iframe must be from the same domain or browser will block any interaction between them.
Upvotes: 0