HTML 4.0 (the predecessor of 4.01) introduced something called frames, which split the browser's viewport up into different sections, each displaying a different, complete webpage. Frames were usually used when one of those webpages displayed something that was used in each page, such as navigation. It was a good idea in concept, but the execution left a few things to be desired. Amongst the litany of woes:
Server-side scripting—explained in Server-Side Scripting—allows for frequently-used code to be placed in its own file but made part of the webpage proper, rather than displayed apart from it.
So why were frames ever used?
For this reason, framesets did see a heyday and are still used, so I will tell you about them.
Just a note here: So far as I can tell, frames only ever worked for HTML pages—although there was an XHTML 1.0 Doctype for frames, they don't seem to work when the file is treated like XHTML.
First off, Frameset (X)HTML has its own Doctype:
Webpages using Strict and Transitional (X)HTML have the following structure within the html
element:
Framesets worked a tad differently:
The head worked as normal, a frameset arranged frames into columns and rows, frames contained references to the pages they were to display, and the last was an element that would act in lieu of a body
element if the browser didn't support frames.
The frameset uses three elements used nowhere else in HTML:
Element Name: frameset
The frameset
element was used to arrange frames in the browser viewport. Framesets could be nested as needed.
rows
or cols
; I'm not sure what would happen if you tried to use both. The only difference between these two attributes is cols
splits the screen into vertically arranged sections; rows
splits the screen into horizontally-arranged sections. They contain a comma-separated list of lengths, either as pixels or percentages, and the default is 100% (one row or column). You can also use an asterisk (*), which means
whatever is left.If you have two lengths expressed with an asterisk, you can place a number before each one to determine the ration of remaining space each should get. Some examples:
All usual event and language attributes are forbidden to this element.
Element Name: frame
The frame
element is what refers to the page or file that's supposed to be included.
The frame
element is an empty element. It has no end tag.
1(if you want a frame border) or
0(if you don't). The default value is
1.
noresize, and is used when you don't want your users to resize the frames (which they normally can do by dragging the borders).
yes, which means that there's always a scrollbar present;
no, which means that the frame can't be scrolled; and
auto, which means that the scrollbar appears when required. The default value is
auto.
All usual event and language attributes are forbidden to this element.
You can set a hyperlink to target a frame in a frameset using an attribute found only in the Transitional Doctype: target
. This attribute could be used in the following elements:
These elements would not be used in the frames page itself, but rather the subpages it displayed. The base
element allowed for a default target to be set for all links on that page. Conversely, the target
attribute apparently has no effect on the link
element. You can only specify one target per hyperlink.
There are four specially reserved names:
The values for both target
and name
follow the same rules as id
, the exceptions being the special target
names mentioned above.
Element Name: noframes
Not all browsers in the heyday of frames supported frames, and thus you had the noframes
element, which was designed to hold a version of the page that didn't use frames, acting in lieu of a body
element. In practice it usually contained a message along the lines of Sorry, your browser doesn't support frames
or wasn't there at all. Nonetheless, that was its purpose, and was usually the last element in the root frameset.
I originally had a fairly basic demonstration of framesets for this book (using nested framesets, explained later in this chapter), but I then realized a better demonstration would be to present this entire book in frames mode. Below is a screenshot of that mode; clicking on it will let you experience frames for yourself.
Below is the code used to create this page. A note on the filepaths: (X)HTML files (framesmode.html
and framenav.html
) are contained in the folder Frames/
, a sibling folder to Chapters/
framesmode.html
)framenav.html
)In the above code, it is the base
element that sets the target the various hyperlinks, but more often a target
attribute was applied to each a
element.
I know I demonstrated only two columns, but three or more columns or rows could be used. Combining columns and rows requires nesting framesets. You can nest them however you like, but if you want a frame to stretch the entire width or height of the screen, place that frame in the outer-most layer of nested framesets. Below, I used nesting to allow myself a horizontal frame that displays the book's title:
You can see the results below:
You can also see the frame that shows the actual chapter dramatically shrinking.
As I said earlier, the target
attribute can only affect one frame at a time—for the most part, that's all that was needed (JavaScript allowed you to change more than one frame at a time). Again, clicking on the picture above allows you to browse the entire book in this particular mode.
Element Name: iframe
While not actually part of Frameset (X)HTML (it's part of Transitional (X)HTML), the iframe
element has a similar purpose, but different rendering. Instead of splitting up the browser's viewport, it creates a smaller viewport
containing the page.
It is not an empty element; besides referring to another page, it may also contain content to be displayed in case the inline frame wasn't supported by the browser.
For the example below, I made a copy of the main page of this book and added an iframe
element to display the chapters of the book. As with the previous examples, clicking on the picture will allow you to browse the book in that page.
iframe
Element Added To The Main Pageiframe
Element Is Just Below #Header div
The inline frame here is bordered in green. Again, I used a base
element to set a general target
attribute (in this case, to show-chap
).
frame
element.iframe
element vertically and horizontally. Its values are:
iframe
element in pixels.iframe
element in pixels.The iframe
element does not use language or event attributes.