CIW Course Revision Site


JavaScript - Controlling Frames in JavaScript

In a Nutshell - CIW Course Section 2, Part A2, Chapter 4

Targeting Frames in JavaScript

Using the form properties self, top, parent and name each frame in a frameset can be referenced to allow properties to be set or read, or functions to be called.

When trying to reference one child frame from another child frame, it will be necessary to go via the parent or top frame when building the reference. For example: to reference child2 from child1 you would type parent.child2, as child1 does not know about child2 but it does know about parent which, in turn, does know about child2.

Frames may be referenced by name or by the frame number within the Frames array. I, personally, prefer to use the name as it makes reading the source easier.

Syntax for Targeting Frames

In a similar manner, a function that is declared in the child frame can be called from the parent, or another child frame: top.frames[1].myFrame1.myFunction().

This functionality will come to good use when you reach the end of section revision assignment, but more on that when we get there.

Design by Stephen

Certified Internet Webmaster

Page last Edited: 10 Nov 2011