Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Inline frames


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</a> 
        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


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.