Javascript routines in iframe invoke from the parent page?

Basically, I have an iframe embedded in a page and the iframe has some javascript routines I need to invoke from the parent page.

Now the opposite is quite simple as you only need to call parent.functionName() but unfortunately I need exactly the opposite of that.

Please note that my problem is not changing the source url of the iframe, but invoking function defined in the iframe.

Assume your iFrame’s id is “targetFrame” and the function you want to call is targetFunction():


You can also access the frame using window.frames instead of document.getElementById.