29

Is it possible for me to setup an iframe so it calls a javascript function available in the window.parent.document scope?

1 Answer 1

59

If I am understanding the question correctly, assuming functionName() is defined within the parent of iframe, you can do this within your iframe:

window.parent.functionName();

This will only work though, if both parent and iframe are on the same domain: http://softwareas.com/cross-domain-communication-with-iframes

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

2 Comments

IMPORTANT: be sure to check out the more modern approach referenced/updated in the above URL (window.postMessage). It has pretty good support.
And a plus on the @Nate answer is that postMessage method is for cross-origin comunicacion. Direct "functionName" not works in cross-origin context.

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.