Pages

Wednesday, 16 May 2012

Frameset, Frame and IFrame Elements in HTML

Frame Element

With frames, you can display more than one HTML document in the same browser window. Each HTML document is called a frame, and each frame is independent of the others.

Disadvantages of using frames:

1. Frames are not expected to be supported in future versions of HTML
2. Frames are difficult to use. (Printing the entire page is difficult).
3. The web developer must keep track of more HTML documents

Frameset Element

The frameset element holds one or more frame elements. Each frame element can hold a separate document. The frameset element states HOW MANY columns or rows there will be in the frameset, and HOW MUCH percentage/pixels of space will occupy each of them.

The <frameset> tag defines a frameset. The <frameset> element holds one or more <frame> elements.

Example: The first column is set to 25% of the width of the browser window. The second column is set to 75% of the width of the browser window. The document "frame_a.htm" is put into the first column, and the document "frame_b.htm" is put into the second column:

<frameset cols="25%,75%">
   <frame src="frame_a.htm" />
   <frame src="frame_b.htm" />
</frameset>

IFrame Element

IFrame defines an inline sub window (frame). An iframe is used to display a web page within a web page.

Syntax: <iframe src="URL"></iframe>

The height and width attributes are used to specify the height and width of the iframe.
The attribute values are specified in pixels by default, but they can also be in percent (like "80%").

Example
<iframe src="demo_iframe.htm" width="200" height="200"></iframe>
The frameborder attribute specifies whether or not to display a border around the iframe.
Set the attribute value to "0" to remove the border:

Example
<iframe src="demo_iframe.htm" frameborder="0"></iframe>

Points to note about Frames, Framesets and IFrames

1. The <frameset> tag is supported in all major browsers.
2. If you want to validate a page containing frames, be sure the <!DOCTYPE> is set to either "HTML Frameset DTD" or "XHTML Frameset DTD".
3. If a frame has visible borders, the user can resize it by dragging the border. To prevent a user from doing this, you can add noresize="noresize" to the <frame> tag.
4. Add the <noframes> tag for browsers that do not support frames.
5. Inline frame is just one “box” that is placed anywhere on browser page. In contrast, frame is a bunch of boxes put together to make one site.
 

No comments:

Post a Comment