Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> HTML >> Snippet

16 Frames


..Basically, a frame is a way to split a web page into multiple, separately controlled windows. Each window can contain
a different URL and may be viewed/scrolled separately from any other frames that are being displayed in the browser.
A common use of frames is to have static content on one side of the browser (such as a menu) and dynamic content
(such as the URLs corresponding to the menu selections) on the other side of the browser.

I'm not a huge fan of frames and I don't use frames on any of the approximately 900 web pages at my site. Because
of the difficulties in navigating, printing and saving a page with frames many surfers feel the same way, but that hasn't
stopped many web site designers from using frames anyways.


Inline Frames
There are two general techniques for using frames. The first is simply to display a second URL in the middle of a web
page. The < iframe > tag is used to do this. Just place the < iframe > tag anywhere in the HTML file and the referenced
URL will be displayed at the location of the tag (just like images are displayed at the point where the < img > tag is embedded.

To make the < iframe > tag work the src attribute must be set, as in the following example:

    < iframe src = "htm-adv.htm" >

There are twelve different attributes of the < iframe > tag that can be used to control how the inline web page is displayed.
The height and width attributes are particularly useful and determine how large an area will be used to display the inline frame.

Here's the HTML code for an inline frame, where a second URL is visible within the frame that is defined as 100x400 in size. The
code that generates the inline frame is also shown. Note that the </ iframe > closing tag must be used even though no
information is found between the tag pair.

  < iframe src = "mypage.htm" height = 100 width = 400 >


Standard Frames
The second approach to using frames is to think of the web page as a table of rectangular areas (cells), where each cell
is a separate URL. Here's the code for a simple, but very useful example. This code creates a web page that has just two
frames, one on the left (called 'left') and one on the right (called 'right'). To get a URL to appear in a frame, the target attribute
of the anchor is set to the frame name. The one on the left is narrow, containing a menu of clickable links. The frame on the
right contains the URL corresponding to the menu item that has been clicked:

    < html >
    < frameset rows = "100%" cols = "20%,80%" >
    < frame src = "mypage.htm" name =left >
    < frame src = "yourpage.htm" name =right >
    </ frameset >
    </ html >

A link such as < a href = "mynewpage.htm" target =left > will put the new page in the left frame.

Other frameset examples:
< frameset cols = "10, * , 10"   'two thin edged with everything else in the center

Without nosize attribute, users can resize frame.  Use this to stop resizing:
< frameset noresize >