|
Here's the rundown on what I'm looking for.
I have a main page. This main page receives a parameter which is a ; delimited list of Javascript files to include. On page load, it takes this parameter, splits it on ';' and writes a <script></script> block in the head to include each file.
This works perfectly.
The main page has an iframe, which includes a page passed as a parameter also. This, again, works fine.
The issue is with the iframe page calling functions defined on the Main page (its parent). If I call a function that's been defined in the parent from the iframe, I get a "function undefined" error, which is to be expected. Adding parent in front of the function works, and it'll call the parent page's function. I don't want to do this.
I want the iframe to trap all functions called from within itself. If the function isn't defined, it'll "move up" and call the function on the parent page. Essentially, this means the child page (in the iframe) can redefine functions, essentially overriding the Main page's, which is exactly what I want to do.
However, while I can trap DOM events such as click, mousedown, etc. using addEventListener, I can't seem to find how to trap a function call (be it all the functions or specific ones).
My questions:
a) Is this possible;
b) If so, can I listen for EVERY function called and pick up the name of the function that was being called from the event object, and use it to call parent.function(). If not, is it possible to add listeners for specific, user-defined functions.
Thanks for your time.
|