Inline frames



January 01, 2002
URL:http://www.drdobbs.com/inline-frames/184411870

WebReview.com: Inline frames

A frame is nothing more than an independent browser window, joined with other frames and framesets to make up a complete browser display. It seems logical that you could create a frame as part of a conventional HTML document, resulting in a "flow within a flow." In fact, the HTML 4.0 standard defines this type of frame, known as an "inline frame."

Inline frames are created using the <iframe> tag. The <iframe> tag accepts the same parameters as the conventional <frame> tag, with a src attribute specifying the URL of the content of the inline frame.

The browser treats the inline frame as a rectangular object that can be placed in a text flow like an image. Accordingly, the <iframe> tag accepts align, height, and width attributes like the <img> tag. This lets you determine the size of the frame and how it's placed in relation to the surrounding text.

Inline frames and tables

If you've followed these columns since the beginning, you know that you can create the same "flow within a flow" effect using a single-cell table within your regular text flow. The content of the table is rendered separately from the other text, like an inline frame, and the table can be aligned relative to the surrounding text, like an inline frame.

The similarities end there. Unlike a table, inline frames load their content from another HTML document, specified with the src attribute. This lets you create and maintain that content independent of the frame displaying it, allowing the same content (a disclaimer, perhaps, or some standard boilerplate) to be created once and displayed in many documents using inline frames.

Since inline frames can be named, links can change the contents of the inline frame on the fly. Tables are static and cannot be changed after the page is rendered. In addition, inline frames support scrollbars, letting you create a small window onto a larger document.

Supporting non-compliant browsers

If inline frames are so great, why don't we see them everywhere? Unfortunately, inline frames were only standardized with HTML 4.0 and only work in current releases of Internet Explorer. When other browsers catch up, inline frames may become more popular as another handy document layout tool.

Until then, you can take advantage of inline frames, provided that you make them compatible with non-compliant browsers. The <iframe> tag has one major difference when compared to the <frame> tag: it has a closing </iframe> tag. Compliant browsers will create the desired inline frame, ignoring the content between the <iframe> and </iframe> tags. Non-compliant browsers will ignore the <iframe> tag and instead display the content.

A well-formed inline frame would look something like this:

     <iframe src="moredata.html" align=right>
        <a href="moredata.html">Additional information 
        is also available.
     </iframe>

This inline frame presents the additional data directly in the current document if the browser is compliant, and provides a link to the same information if the browser is not.


Previously in Tag of the Week:

Basic Target Behaviors
Linking Between Frames
Controlling Individual Frames

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.