Named Frames, the Target Attribute, and Iframes

Advanced Frames Techniques

Sample framed page
Sample framed page. Jennifer Kyrnin

The most common use of frames is also what makes them the most useful, putting up a table of contents on the side or the top of the frame. But how do you get the frames to open in a different window when you click on them?

Naming Frames

When you are describing the frames in your frameset, one of the attributes is the frame name (as described in part 3). Once you have named a frame, it can become the destination for any link in any other frame.

To accomplish this, you use the TARGET attribute in your anchor tag.

To return to the sample framed site, in part 1, we created a frame.html page. In order to open links in the navigate.html page, I need to name the frames in the frameset:
<html>
<head>
<title>A Sample Framed Page</title>
</head>
<frameset rows="50,*">
 <frame src="/tmc/navigate.html" name="navigate">
 <frame src="/tmc/body.html" name="contents">
 <noframes>
 This is a framed page, please go to <a href="/tmc/body.html">the body page</a> for more information.
 </noframes>
</frameset>
</html>

Then, every link in the navigate.html page that I want to open in the body.html frame would have a target of contents, for example:
<a href="http://webdesign.about.com/" target="contents">About</a>

Note: If you target a link to a frame name that doesn't exist, the browser will open a new window and give that window the specified name. After that, all anchors linked to that target will open in the new window.

Special Targets

There are four reserved target names that do special actions in the browser:_blankThis loads the linked document into a new browser window with no name._selfThis is the default action for all anchor tags. Any linked document with this target will load into the same window as the link.

The only time this target is not redundant in when it's used in the base tag in a document head._parentThis target causes the linked document to be loaded into the parent window or frameset. If there is only one frameset, the document will be loaded into the browser window. If there are nested framesets, the document will be loaded into the next level frameset up._topThis target removes all framesets and loads the linked document into the top level window of the browser.

Note: All of these targets begin with the underscore (_) character. Do not use an underscore as the first character of a target name. The browser will ignore all targets starting with underscore other than the four named above.

The base Default Target

This is an easy way to specify the default target for all of your links on a page. Instead of naming the target in every link, you simply put the base tag in the <head> portion of your document:
<html>
<head>
<title>Title</title>
<base target="contents">
</head>

All links in the above document would automatically load in the contents frame, unless I specifically name a different target.

The Inline Frame

Advanced browsers let you define a frame from within the middle of a conventional document, just like you might define an image or multi-media element.

The iframe tag is not used within a frameset, but within a document anywhere you might use the img tag. The primary difference is that it requires an ending /iframe tag.

When you use an iframe tag, it's best to put explanatory information in the contents of the tag for other browsers. Inline frames compliant browsers will ignore these comments, while other browsers ignore the iframe tag and display the contents.

Here is an example of the HTML for an inline frame:
...preceding content
<iframe src="body.html" width=200 height=100 align=right>
You are not using Internet Explorer or an IFrames compliant browser. To view this <a
href="body.html">in-line frame</a> correctly, you'll need
an iframe compliant browser.
</iframe>
...following content

You can see this page at bl_inline.htm. Be sure to use Internet Explorer or Mozilla or another inline frames compliant browser.