HTML and CSS Reference
In-Depth Information
EXAMPLE 10.17 ( CONTINUED )
<body bgColor="white">
<h3>
Pick a color:
<br />
3
<a href="JavaScript:setBgColor('red')">red</a>
<br />
<a href="JavaScript:setBgColor('yellow')">yellow</a>
<br />
<a href="JavaScript:setBgColor('green')">green</a>
<br />
<a href="JavaScript:setBgColor('blue')">blue</a>
</h3>
</body>
</html>
------------------------------------------------------------------
<html>
<head><title>Right Frame</title></head>
<body>
<h2>
This is the frame where colors are changing.<br />
In your JavaScript function, this is frame[1].
</h2>
</body>
</html>
EXPLANATION
1
A function called setBgColor() is defined. It takes one parameter, a reference to a
color being passed by the user.
2
Going down the document tree, start with the parent window, to the second
frame, frames[1] (remember array subscripts start at 0), to the frame's document,
and then the document's property, bgColor. Assign a color . This assignment will
cause the background color in the right frame to change.
3
When the user clicks any of the following links, the JavaScript function setBgCol-
or() will be called, with the color sent as an argument to the function. The Java-
Script: pseudo URL prevents the link from going to a real URL. The display is
shown in Figure 10.28 on page 311.
Using the top Property to Keep the Main Window Out of a Frame. When the
user loads your Web page into his or her browser, he or she may load it into a frame
rather than in the main window. You might not want this, as framesets create states in
the browser that are not addressable. For example the user might not be able to book-
mark your page or reference it with the current URL once the frame content changes.
See more on this at http://htmlhelp.com/faq/html/frames.html#frame-problems . You can
use the location method to force your page to load in the main window by putting the
 
Search WWH ::




Custom Search