Working with FramesWindows can appear in frames in HTML. Some people love frames, some hate them, but there's little question that they're here to stay. You use the <FRAMESET> and <FRAME> HTML elements to create frames, and because the window object has many properties designed to be used with frames, I'll take a look at the <FRAMESET> and <FRAME> elements in this chapter. Feeling rusty on frames? Here's an example to get us started; this example, Listing 07-07.html on the web site, displays three HTML documents (Listings 07-08.html, 07-09.html, and 07-10.html) in various frames using <FRAMESET> and <FRAME> : (Listing 07-07.html on the web site)<HTML> <HEAD> <TITLE>Working With Frames</TITLE> </HEAD> <FRAMESET COLS = "55%, 45%"> <NOFRAMES>Sorry, your browser does not support frames!</NOFRAMES> <FRAMESET ROWS = "35%, 45%, 45%"> <FRAME SRC="07-08.html"> <FRAME SRC="07-09.html"> <FRAME SRC="07-10.html"> </FRAMESET> <FRAMESET ROWS = "25%, 25%, 50%"> <FRAME SRC="07-08.html"> <FRAME SRC="07-09.html"> <FRAME SRC="07-10.html"> </FRAMESET> </FRAMESET> </HTML> (Listing 07-08.html on the web site)<HTML> <HEAD> <TITLE> Page 1 </TITLE> </HEAD> <BODY BGCOLOR="RED"> <H1> Page 1 </H1> Here is page 1. </BODY> </HTML> (Listing 07-09.html on the web site)<HTML> <HEAD> <TITLE> Page 2 </TITLE> </HEAD> <BODY BGCOLOR="YELLOW"> <H1> Page 2 </H1> Here is page 2. </BODY> </HTML> (Listing 07-10.html on the web site)<HTML> <HEAD> <TITLE> Page 3 </TITLE> </HEAD> <BODY BGCOLOR="CYAN"> <H1> Page 3 </H1> Here is page 3. </BODY> </HTML> You can see the results in Figure 7.8, where we're displaying various documents in frames. Figure 7.8. Working with frames.
The main frame element is the <FRAMESET> element, and I'll take a look at working with this element in JavaScript nowincluding showing how to create new frames entirely in JavaScript. |