HTML Frames

To refresh our memory of HTML, we will now take a quick look at a few different HTML techniques. Since this course is concentrating on client-side web design, we will look at a few techniques that are often used by web designers. The first technique we will look at is frames. Frames were designed to divide a browser window into several rectangular areas, where each area can contain a separate web page, and the content of each area can be changed.

There are only 3 tags that you need to learn to use frames. They are frameset, frame, and noframes. There are also two steps you have to follow. The first step is to create an HTML document which defines the frames and specifies what content will be loaded into each of them. The second step is to create the content for the frames, which consists of ordinary web pages.

<frameset>

Usage: <frameset attributes> ... frame info ... </frameset>

You can have a head element before a frameset, but no body element. Framesets can also be nested to create complex setups

Attributes:

<frame>

Usage: <frame attributes>

Attributes:

<noframes>

Usage: <noframes attributes> ... content ... </noframes>

Used to display content in frames-challenged browsers. Use only in the outermost frameset.

Attributes:

A template for creating frames

<html>
<head>
<title>Frame Test</title>
</head>
<frameset rows="70, *" cols="*,50%,*" >
   <frame src="frm1.html">
   <frame src="frm2.html">
   <frame src="frm1.html">
   <frame src="frm2.html">
   <frame src="frm1.html">
   <frame src="frm2.html">
   <noframes>
      <p>You don't have a browser with frame capability.  If you
         did, you would be seeing 6 frames right now.</p>
   </noframes>
</frameset>
</html>

Sending content to frames

It is rather easy to send content to a frame if it has a name (set with the name attribute). Just add the target attribute to an anchor tag and set the value equal to the name of the frame.

For example, clicking on the following link will send the contents of the page page1.html to the frame named content_frame.

<a href="page1.html" target="content_frame">link text</a>

Special Target Frame Names

Using the BASE tag with frames

You can set the target for all the links in a page by setting the target attribute of the base tag. Remember that the base tag is in the head element of the document. The target can be overridden by supplying a specific target with the particular link. This trick can be used to make sure you don't trap your visitors by setting up external links inside one of your frames. Just set target="_top" in a base tag in the head element. Every link in the document will wipe out frames unless specifically told not to.

Inline frames

Inline frames are something that would be nice to have available. They are now part of the HTML 4.0 standard and are implemented by Internet Explorer. For the moment, however, it is probably best to stay away from them.

Inline frames are placed within a document just like an image. The frame scrolls with the document. They are also specified within the document.

<iframe>

Usage: <iframe attributes>...content...</iframe>

Attributes:

Sample pages

W3Schools frames tutorial

http://www.w3schools.com/html/html_frames.asp opens in a new window.

Frame Exercise

Frame exercise opens in new window.

Previous: HTML Resources

Next: HTML Tables