Entry
How do I reference frames within frames?
How do I access a frame in a frameset document that loads in a frame of a higher-level frameset?
Aug 13th, 2000 03:09
Rey Nuņez,
You can use the frames collection, which retrieves a collection of all
window objects defined by the document, that can be referenced by
index, name or ID.
window.frames[0]
window.frames['frameName']
window.frames['frameID']
If the HTML source document contains a BODY tag, the collection
contains one window for each IFRAME object in the document. If the
source document contains FRAMESET tags, the collection contains one
window for each FRAME tag in the document. In both cases, the order is
determined by the HTML source.
Note that this collection contains window objects only, and does not
provide access to the corresponding FRAME, meaning you can use only
window object properties, such as location, etc. and not FRAME object
properties such as src, etc.
The below code snippet, which must be run from one of the pages loaded
in the frameset, displays the URLs of the documents contained in each
frame in a FRAMESET document.
var frms = window.parent.frames;
for (i=0; i < frms.length; i++)
alert ( frms(i).location );
Now, if a frame loads another frameset document (which has its own
collection of frames), we need to nest the reference in the following
way. To access a frame (in a frameset doc) that is loaded in a frame in
a higher level frameset doc, use the below code snippet, which must be
run from any of the pages that loads in the higher level frameset:
window.parent.frames['frameName'].frames['frameName'].location;