Section 14.4. Targeting Frames


14.4. Targeting Frames

One of the challenges of managing a framed document is coordinating where linked documents display. By default, a linked document loads into the same window as the link; however, it is often desirable to have a link in one frame load a page into a different frame in the frameset. For instance, this is the desired effect for a list of navigation links in a narrow frame that loads content into a larger main frame on the page.

To load a new linked page into a particular frame, you first need to assign a name to the targeted frame using the name attribute in the frame element, as follows:

 <frame src="/books/4/439/1/html/2/original.html" name="main" /> 

Names must start with a letter (upper- or lowercase).


Now you can specify that frame by name within any anchor (a) element with the target attribute, as shown in this example:

 <a href="new.html" target="main">...</a> 

In this example, the document new.html will load into the frame named "main."

If a link contains a target name that does not exist in the frameset, a new browser window is opened to display the document, and that window is given the target's name. Subsequent links targeted to the same name will load in that window.

14.4.1. The base Element

If you know that you want all the links in a given document to load in the same frame (such as from a table of contents into a main display frame), you can set the target once using the base element instead of setting the target within every link in the document (saving a lot of typing and extra characters in the HTML document).

Placing the base element in the head of the document, with the target frame specified by name, causes all the links in the document to load into that frame. The following is a sample targeted base element:

     <head>     <base target="main" />     </head> 

Targets set in individual links override the target set in the base element at the document level.

14.4.2. Reserved Target Names

There are four standard target names for special redirection actions. Note that all of them begin with the underscore ( _ ) character. Do not give your frames names beginning with an underscore, as they will be ignored by the browser (names must start with a letter). The four reserved target names are:


_blank

A link with target="_blank" opens a new, unnamed browser window to display the linked document. Each time a link that targets _blank is opened, it launches a new window, potentially leaving the user with a mess of open windows. Note that this value can be used with any link, not just those in a frames context.

Opening pages in new windows is problematic for accessibility. When opening a document in a new window, be sure to include a note that says "link opens in a new window" or something similar. This gives all users, but particularly those with non-visual browsers who won't see a new window open, a heads-up that the context of the page is going to change.



_self

This is the default target for all a elements; it loads the linked document into the same frame or window as the source document. Because it is the default, it is not necessary to use it with individual a elements, but it may be useful for the base element.


_parent

A linked document with target="_parent" loads into the parent frame (one step up in the frame hierarchy). If the link is already at the top-level frame or window, it is equivalent to _self. Figure 14-7 demonstrates the effects of a link targeting the parent frame.

The _parent target name works only when the nested framesets are in separate documents. It does not work for multiple nested framesets within a single frameset document as shown in Figure 14-4.

Figure 14-7. In nested framesets, the _parent target links to the parent frameset


_top

This causes the document to load at the top-level window containing the link, replacing any frames currently displayed. A linked document with target="_top" "busts out" of its frameset and is displayed directly in the browser window, as shown in Figure 14-8.

Links to other web sites should use the target attribute set to _top or another named window to prevent the site from loading within the current frameset.


Figure 14-8. Linking with the _top target replaces the entire frameset





Web Design in a Nutshell
Web Design in a Nutshell: A Desktop Quick Reference (In a Nutshell (OReilly))
ISBN: 0596009879
EAN: 2147483647
Year: 2006
Pages: 325

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net