Because of the widget format I\'m working with I have a page which has multiple iframes embedded within iframes. I won\'t paste the code as it\'s vast and unwieldy but it is
EDITED
This returns an iframe
element which has the wanted id
, and null
, if the wanted id
is not found.
function searchIds(wantedId) {
var idArray = [], n,
search = function (iframes) {
var n;
for (n = 0; n < iframes.length; n++) {
if (iframes[n].frames.length > 0) {
search(iframes[n].frames);
}
idArray.push(iframes[n].frameElement.id);
idArray.push(iframes[n].frameElement);
}
};
search(window.top.frames);
for (n = 0; n < idArray.length; n += 2) {
if (idArray[n] === wantedId) {
return idArray[n + 1];
}
}
return null;
}
Notice, that searchIds()
can't be run before onload
of the main window has been fired.