|
|
|||||||||||||||
|
|
Frames | Naming Frames |
|
|
|
|||||||||||
Naming Frames
|
|||||||||||||||
<frameset rows="20%,80%"> |
Here we've given our two frames the (not very imaginative) names frame1 and frame2. We can name our frames just about anything we want, as long as use only alphanumeric characters in forming the names. There are a few "reserved" frame names that have special meanings; we'll look at these names later.
Once a frame has been named, it can be "targeted". That is, links in other frames can be instructed to open files in a named frame, rather than obeying their default behavior (which generally means opening in the frame where the link is located).
Perhaps this targeting behavior sounds a bit familiar? If you've already looked at this tutorial's discussion of targeting links to open in new browser windows (or if you've already had experience doing this), you may now be getting a feeling of deja vu all over again.
In the discussion of opening links in other windows
(either new or pre-existing, but not the window containing the link), we see that
it is possible to
target a link in one window to open
a file in another window. We can do this with HTML by
adding the TARGET attribute to a link; for example, this
link opens in the current window.
The link uses the standard sort of <a> tag that we've
had lots of experience with by now:
<a href="linked.html">link</a>
but this
link
opens the file named linked.html in a new window that we have named (again unimaginatively) newwin.
This latter link was coded as
<a href="linked.html" target="newwin">link</a>
In our discussion of opening files in other windows
we see that we can also use JavaScript to accomplish the targeting.
As far as targeting links is concerned, frames are treated the same as windows.
Just as we can target a link to open in a named window either by adding the
TARGET attribute to an HTML <a> tag, or by using the JavaScript
window.open function, we can also use either approach to open
a linked file in a named frame.
In both cases, if the named window or frame is already open, the linked file will be loaded
into the window or frame when the link is clicked.
If no window or frame with the specified name
is already open, a window
with that name will be created and the linked file opened in it
when the link is clicked.
(Frame sets cannot be spontaneously created by opening new links.
They can only be created in the way we described earlier in this chapter.
From the earlier discussion is should be obvious why this is true.)
A Simple Example of Targeting Links
As we mentioned earlier, one of the most common uses of frames is to create a set of two frames, with one serving as a table of contents that is always displayed. This frame has links to material that gets displayed in the other frame of the set. For the sake of future reference, let's call these the toc frame (for "table of contents") and display frame, respectively. You learned earlier how to create such a simple frame set. And now you know how links in the toc frame can be targeted into the display frame.
To implement a very simple example of such a frame set let's create an enhancement of Example 2. We start with the set of named frames that we looked at in the previous section (which is Example 2 modified to use named frames). Now we make an additional modification to the frame set: instead of loading file2.html into the second frame, we load a file there that contains a collection of targeted links. The new frame set is now:
<frameset rows="20%,80%"> |
The file with our list of targeted links
is named toc.html; it contains:
|
Here is the result:
Example 12.
By clicking on a link in the toc frame we load a new file into the display frame.
Special Reserved Names for Link Targets
While you can generally name a frame or window about anything you wish,
there are four reserved names that have special significance
when used as targets of links:
_blank, _self, _parent, and _top.
(Note that each of these names begins with the underscore character.)
Note that since _blank opens a file in a new unnamed window, that window can't be targeted for other links. So if you try to target several links with _blank, each will open in a separate new window.