Ok so lets say I have a webpage, webpage B. Webpage B has a function called “test()”. Now lets say I have another webpage, webpage A. Webpage A has an iFrame with the source of webpage B. How can I execute webpage B’s “test()” function from webpage A?
Share
You cannot ‘directly’ control the javascript of a page within an iframe by any code in the parent page.
If however you have the ability to change both pages, you can change ‘page B’ to run javascript based on parameters in it’s query string.
In ‘page A’ Set the iframe src to something like:
http://mydomain.com/pageb.html?func=myfunc¶m=foo¶m2=barThen in ‘page B’ run some javascript like this:
This is of course a very basic example, but can be adapted to do all kinds of crazy stuff. The limitation is that you can’t really pass messages back to ‘page A’, although you ‘could’ (I think) adapt the technique in page A then call
top.location = 'pagea.html?message=foo'(like how frame-breaking works).