Solution to find a frame by name in the frame hierarchy

D

Daniel Frede

<script>try {
var frame1;
frame1=find('myFrameNameToFindInHierarchy',getFrame('myTopFrameName', window));
//debugger;
alert(frame1.name);
//Do something with the frame
frame1.document.location.reload;

}catch (e) {};


// Get frame by framename (recurse down)
function find(what,current) {
var ret;
for (var i=0;i<current.frames.length;i++) {
if (current.frames.name == what){
return current.frames;
}
ret = find(what,current.frames);
}
return ret
}


// Get top frame by name (recurse up)
function getFrame(TopFrameName, currentWindow){
if (currentWindow.name == TopFrameName){
return currentWindow;
}
if (currentWindow.name == currentWindow.parent.name){
return getFrame(TopFrameName, currentWindow.opener);
} return getFrame(TopFrameName, currentWindow.parent);
}

</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top