Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

Named Frames, the Target Attribute, and Iframes

Advanced Frames Techniques

By Jennifer Kyrnin, About.com

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"&#62;the body page</a> for more information.
&#160;</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 &#9name._selfThis is the default action for all anchor tags. Any linked &#9document with this target will load into the same window as the &#9link. The only time this target is not redundant in when it's used in &#9the base tag in a document head._parentThis target causes the linked document to be loaded into the &#9parent window or frameset. If there is only one frameset, the document &#9will be loaded into the browser window. If there are nested framesets, &#9the document will be loaded into the next level frameset up._topThis target removes all framesets and loads the linked document &#9into 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.

Explore Web Design / HTML

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. About.com Web Design A to Z
  5. Web Design Articles A-H
  6. Web Design/HTML Articles C
  7. Named Frames, the Target Attribute, and Iframes

©2009 About.com, a part of The New York Times Company.

All rights reserved.