Implementing Frames in XHTML

As in HTML, frames have a singular purpose in XHTML: to give you, the author, the ability to present to the user multiple documents at the same time. This can be done through two methods: fixed frames and floating frames.

 Fixed frames allow you to divide the screen into regions; subsequently, you indicate which document displays in each region. To do this, you must first create the individ- ual document, then a frameset document that includes the code that details how to divide the window, and instructs the browser which document to display in which frame. Thus, you will be creating n+1 pages. n being the number of documents to be displayed; the plus-one document being the frameset document. So, to create a page that displays three documents, for example, you must create four documents, the three that will display, plus the frameset document.

The other method of displaying multiple documents to use a floating frame. In this case you create a document as usual, then create a floating frame, which is a space in the larger document that contains another document. Using this method, you create only the number of documents you wish to display. No frameset document is involved, as the floating frame is coded directly into the larger document.

Coding Fixed Frames

The only items that have changed in the coding of frames in XHTML are the larger issues, such as lowercase elements and quoted attribute values, the elements and attributes have not changed from HTML to XHTML.


 A frameset document tells the browser how to split up the window, and in which frame to display which document. Frameset documents start out as nonframe docu- ments, do as shown here (be sure to change your !DOCTYPE statement to the one needed for a frameset document):



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml1- frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Simple html document to be converted to xhtml</title>
</head>
...
</html>




But note that, in a frameset document, there is no <body>. Instead, you must use the <frameset> element. In fact, in most instances, if you do include the <body> element after </head>, any frameset information will be ignored by the browser. Thus, you can regard the <frameset> element as a replacement for the body element. Adding the <frameset> element, we end up with the following code:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Simple html document to be converted to xhtml</title>
</head>
162 Chapter 7
<frameset>
...
</frameset>
</html>


Nested within <frameset>...</frameset>, only three other elements may appear:
<frame>. Used to establish the window areas.
<noframe>. Used to display alternate information for browsers that do not sup- port frames.
<frameset>. Used for combining rows and columns.





We will deal with each of these elements in turn. Just adding the <frameset> element does not tell the browser anything that it needs to know. It’s similar to inserting an <img> element without specifying the src attrib- ute. So, in this case, we also have an element that is required to actually accomplish anything. The two attributes that you have to choose from to use with <frameset> are rows and cols. Which you use depends on the direction in which you would like to divide the browser window. To help you make this decision, it’s a good idea to first take pen- cil and paper and sketch out what you want the browser window to look like. Doing so will make it much easier to code your frameset document and keep track of which frame is which. To start, we’ll work with rows. Let’s say we want to create a window that displays two documents. The first document will display in the top 25 percent of the window, and the second will take up the bottom 75 percent of the window. Following is the code we’ll use to divide our window into two portions:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Simple html document to be converted to xhtml</title>
</head>
<frameset rows="25%, 75%">
...
</frameset>
</html>


Because we have used the rows attribute, the browser will generate two frames, divided horizontally, based on the percentages we assigned. If we had used the cols attribute, the frames would have been established vertically.


No comments:

Post a Comment