HomeDHTML Page 5 - Rough Guide To The DOM (part 2)
In The Frame - DHTML
In order to illustrate how to navigate across frames, I'm
going to write a simple script which changes the background colour of the right frame when the appropriate link is clicked in the left frame. Here's the right frame
Finally, let's take a look at the function which does all
var bodyObj = top.right.document.getElementById("body");
Since this is a frameset, it's necessary to prefix the
document.getElementById() method call with a reference to the appropriate frame. This prefix is necessary to identify to the DOM which frame is being called, and to obtain a reference to the correct document tree.
Once a reference to the right frame's <body> tag is obtained, changing the frame's background colour is a simple setAttribute() away.
This article copyright Melonfire 2001. All rights reserved.