Posted by Jonathan Brownell on September 15, 1998 at 12:26:41:
In Reply to: Frames and scripting posted by Steve Gonzales on September 15, 1998 at 12:01:47:
Steve - this problem might seem like a real toughie, but the JS programmers anticipated our needs here and made it pretty easy to do. Let's create a hypothetical situation:
Frame 1 is the side bar, with a [frame name="sidebar"]. (Pardon the use of brackets instead of actual HTML signs.) It contains several [a href="whatever" onClick="This code needs to set one of Frame 2's variables"] tags.
Frame 2 is the main content frame, with a [frame name="content"]. It contains a script variable called "myVar" that needs to be set by the links in Frame 1.
To solve the communication problem here, we have to use the browser's object model to access the frames. Because the two frames are automatically inserted into the window hierarchy, it's easy to access them using scripts:
[script language="Javascript"]
top.content.myVar="Value";
[/script]
Wasn't that painless? See how the frames can all be accessed as
child windows of the 'top' object? Now, all that's left is to
incorporate this code into the sidebar links:
[a href="#" onClick="top.content.myVar='Home';"]Home[/a]
[a href="#" onClick="top.content.myVar='Products';"]Products[/a]
[a href="#" onClick="top.content.myVar='Contact';"]Contact Us[/a]
Let me clarify one more thing here: the href="#" parameters that I
used above tell the browser not to load any new pages when the link
is clicked, but still execute scripts. If href="", then the link is
ignored and no scripts are run at all.
This final code should solve your problems. If you have any more questions, don't hesitate to post!
-Jonathan Brownell