Frameset Communication

A common problem that occurs with frames is that child frame one was trying to talk to child frame two, but child frame two hadn't loaded up yet... so it produced an error.

The general rule of thumb is never communicate with a frame until you KNOW it is loaded. How do you know a frame is loaded? Can you just assume that the frames load in order of appearance on the page? Well, you could in some older browsers, but some programmer over at Netscape decided that the order in which frames loaded wasn't all that important, so he removed that feature. So you can never be sure that the frames will be loaded in order.

For example, if your display frame needs some info from your data frame, your data frame needs to let the display frame know as soon as it is ready (loaded). But what if the display frame is downloaded before the data frame? Can JavaScript just tell it to pause and wait until the data frame is loaded? Yes and no. It depends on whether you need to make document.write() calls in your display frame.

Any document.write() calls must be called inline as the page is being loaded. And you can't just tell the page to pause in loading until you are ready, either. Once a page is completed loading, if you call document.write(), it will clear the page (not just add the stuff to the bottom as you might suspect).

The first way basic way is that you must load a filler frame in place of the display frame. Then, when the data frame is loaded, JavaScript triggers the load of display frame.

The second category of frame communication doesn't involve any document.write() calls in the display frame. Now once a frame is loaded, JavaScript can pause and wait for the data until the data frame is ready.

The key to both of these solutions hinges on this one concept: Since you don't know in which order the child frames will be loaded, the only sure thing is for a child frame to talk to the parent frameset. Because the parent frameset must be loaded before the child frames, it must serve as the master controller.