Working with frames and hypertext links

To control the behavior of hyperlinks in a framed page, there are two required steps:

  1. give each frame of the page a name
  2. point each hypertext link to one of the named frames

To assign a name to a frame, add the name attribute to the frame tag. The syntax for this attribute is:

<frame src="URL" name="frame_name" />

where frame_name is any single word you assign to the frame tag. The name is CASE SENSITIVE.




Specifying a link target

The target attribute of the anchor tag <a> specifies a frame where the document will be loaded. The syntax for this is:

<a href="URL" target="frame_name" />

where frame_name is the name you have assigned to a frame.

The <base> tag is used within the <head> tags of your HTML file and is intended to specify global options for the page. The syntax of this attribute is:

<base target="frame_name" />

Click the button to open a pop-up window with two frames:

 

This layout is produced by the following HTML files:

Frameset definitionLeft frame
<html>
<frameset cols="*,*">
 <frame src="lframe2.html" name="left" />
 <frame src="rframe2.html" name="right" />
</frameset>
</html>
<html><head>
<base target="right" />
</head>
<body bgcolor="orange">
<a href="rframe2.html">
 Open document 1</a><p>
<a href="rframe3.html">
 Open document 2</a><p>
<a href="rframe2.html"
  target="left">
 Load document 1 here</a>
</body>
</html>




Using reserved target names

Reserved target names are special names that can be used in place of a frame name as the target. They are described in the following table:

Target nameComments
_blank loads the document into a new browser window
_self loads the document into the same frame or window that contains the hypertext link tag
_parent loads the document into the frame that contains the frame with the hyperlink tag
_top loads the document into the full display area replacing the frame layout

Note that the reserved target names are CASE-SENSITIVE.

Example: consider the following frame definitions:

Top framesetFile rframe4.html
<html>
<frameset rows="30%,*">
 <frame src="rframe2.html" />
 <frame src="rframe4.html" />
</frameset>
</html>
<html>
<frameset cols="*,*">
 <frame src="rframe2.html" />
 <frame src="rframe2.html" />
</frameset>
</html>

By clicking one of the buttons below opens a pop-up window. The document in the right bottom frame of this window will be replaced with a new one, which contains a link with the corresponding setting of the target attribute. Clicking on this link in the frame causes downloading another document into the corresponding frame.