N
news
I have a document that can contain any number of iframes which have
further copies of the same document (and so on). In practice, we
shouldn't ever have frames within frames, but I'd like to make the
implementation a general case.
Various of the functions in the parent document need to call themselves
in the child documents with the same parameters as they've just been
passed.
Now, I can stick a loop in each function that goes throught the
window.frames array and calls the function for each frame, but for I'd
like to write a function to do this.
It's at this point that my brain explodes. If I limit it to a single
parameter we can do:
function functionExists(funcName, win) {
win = win?win:window;
return (win[funcName] && typeof win[funcName] == 'function');
}
function forEachChild(funcName, param) {
if (functionExists(funcName)) {
window[funcName](param);
if (window.frames && window.frames.length) {
for(var i = 0, L = window.frames.length; i<L; i++) {
if (functionExists('forEachChild', window.frames)) {
window.frames.forEachChild(func, param);
}
}
}
}
}
But how do I expand that to any number of parameters? Passing functions
by their name rather than as an object seems a bit naff too. Any ideas?
further copies of the same document (and so on). In practice, we
shouldn't ever have frames within frames, but I'd like to make the
implementation a general case.
Various of the functions in the parent document need to call themselves
in the child documents with the same parameters as they've just been
passed.
Now, I can stick a loop in each function that goes throught the
window.frames array and calls the function for each frame, but for I'd
like to write a function to do this.
It's at this point that my brain explodes. If I limit it to a single
parameter we can do:
function functionExists(funcName, win) {
win = win?win:window;
return (win[funcName] && typeof win[funcName] == 'function');
}
function forEachChild(funcName, param) {
if (functionExists(funcName)) {
window[funcName](param);
if (window.frames && window.frames.length) {
for(var i = 0, L = window.frames.length; i<L; i++) {
if (functionExists('forEachChild', window.frames)) {
window.frames.forEachChild(func, param);
}
}
}
}
}
But how do I expand that to any number of parameters? Passing functions
by their name rather than as an object seems a bit naff too. Any ideas?