|
|
|||||||||||||||
|
|
Advanced Methods | Naming Frames |
|
|
|
|||||||||||
|
Naming Frames and Targeting Links
Another often useful attribute that we can include in the frame tag is NAME. Aptly named, this attribute allows us to name a frame. We'll see in in a moment how the name can be used. Here's an example of naming frames:
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).
Does something about this sound a bit familiar?
Maybe you'll remember our
earlier discussion
of opening links in windows other than the one that contained the link.
There we saw it was 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
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
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:
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
|
|||||||||||||||
|
|
|||||||||||||||