WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 getElementsByTagName recursively through iframes, Michael Sheakoski, September 16, 2003
     Re:getElementsByTagName recursively through iframes, Erik Arvidsson, September 16, 2003
         Re:getElementsByTagName recursively through iframes, Michael Sheakoski, September 19, 2003
             Re:getElementsByTagName recursively through iframes, Erik Arvidsson, September 20, 2003

Subject: Re:getElementsByTagName recursively through iframes From: Michael Sheakoski Date: September 19, 2003

Thank you once again Erik.  You mentioned that these were standard patterns.  Did you find such pattern information in a book/class?  Any recommendations?  It almost seems pointless to buy a book on DHTML since the best practices are constantly changing, just thought I would ask.

thanks,
-Mike

From: Erik Arvidsson
Sent: September 16, 2003
Subject: Re:getElementsByTagName recursively through iframes

Use the standard tree depth pattern for the frame depth

function getFrameDepth(f) {
if (f == f.top) return 0;
return 1 + getFrameDepth(f.parent);
}

alert(getFrameDepth(window));

To find all elements (of some kind) in all frames use another well defined tree algorithm (depth first or breadth first search). The problem is just to translate the NodeList collection to a JS Array.

function getElements(f, sTagName) {
var res = [];
var els = f.document.getElementsByTagName(sTagName);
// translate
var l = els.length;
for (var i = 0; i < l; i++)
res[i] = els[i];
// go through frames
l = f.frames.length;
for (i = 0; i < l; i++)
res = res.concat( getElements(f.frames[i], sTagName) );
return res;
}

(This of course works in all browsers with DOM0 and DOM1 support.)

erik





Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX