Frames and Location

I must admit up front that I’m not fond of frames. Yes, they are extremely useful, and still a terrific way to manage applications in which an action in the left window (or top window) can trigger a change in the right (or bottom). Each can then scroll separately, without any effort on our part.

However, too many companies had (or still have) a habit of opening up other web sites into frames, which basically wrapped the other site’s content in their own environment. Most of us didn’t care for this. Luckily, thanks to JavaScript, we can defeat this technique using a second window object, location.

The location object stores information about the current location and provides a small set of routines to load a new document or replace whichever document is currently loaded.

The frame object has a few properties and methods, and is primarily a subset of the window object. This makes sense considering that each is a window, in miniature. Among the objects supported are frames, name, length, parent, and self. The methods supported are blur, focus, setInterval, clearInterval, setTimeout, and clearTimeout. Of these, the ones new to this example are parent, which would be the parent frameset, length for length of frame, and name, which is the frame name.

The name and parent are particularly important for cross-frame communication. A parent frameset can access each child frame through its name (or through the frames array using the number of the object as an index); each ...

Get Learning JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.