Newsletter sign-up
View all newsletters

Sign up for our Enterprise Java Newsletter

Enterprise Java

JavaScript and Netscape Frames

Site creators get greater control over content presentation

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
In the last issue we discovered JavaScript, the new language that allows HTML developers to take their pages and forms one step closer to interactivity and client-side programming. Now that we have learned the basic JavaScript syntax, we are ready to tackle the job developing useful JavaScripts.

In this article we will be looking at some examples of useful programs that can be written and how they are written. With these examples in hand, you should have the confidence to try some programs of your own. We will also talk more about multiple frames with JavaScript, event handlers, and objects and how they are used in this issue.

Netscape Frames

Netscape did a very nice thing by adding frames capability to the list of possible document characteristics. Although still considered non-standard (i.e., it hasn't been approved by the World Wide Web consortium and the IETF), frames allow creation of multiple document windows within one browser. Each frame appears to act like a separate browser windows, displaying multiple information sources simultaneously. Within each frame you can scroll up and down, and perform all the things that you would normally do within a single browser window. Frames allow you to create a complex document that can help you present information in a more useful manner.

Additionally, the links in a frame can control what is displayed in other frames or windows. This helps you create indices or quick tabs that allow easier navigation through a single document or groups of documents. When a user clicks a link in the index frame it can cause a different page to appear within another frame. The advantage here is that the index frame is always available to the user.

With JavaScript, this control becomes even more useful. Although the browser cannot re-render a page that has already been brought up, you can send the other frames off to display new URLs or information. You can also access resources such as input fields and other form elements in the other frames. With this you can set events to change information in the other frames easily. We will quickly go over the Netscape FRAME system so that I know that we're on the same track. If you're going to use JavaScript, this new document system will come in very handy.

Within the HTML you can now define a set of FRAMEs that constitute the virtual page. Each FRAME can contain its own text that is independent from the others or can refer to another HTML file to be displayed within itself. To maintain compatibility with older browsers, there is a NOFRAMES tag pair that displays alternative pages on the screen of non-Netscape 2.0 browsers. To have real compatibility, you should have a frame reference a separate HTML file for itself. Let's begin by defining the parent page:

<HTML>
<HEAD>
<TITLE>A Framed Document</TITLE>
</HEAD>
<FRAMESET ROWS="25%,50%,25%">
<NOFRAMES>
This text is a placeholder for other non-Netscape 2.0 browsers. You will need a 
version of Netscape 2.0 or a browser that is compatible with Netscape 
FRAMEs to see this page properly. <P>
</NOFRAMES>
    <FRAME NAME="Header" SRC="FRHead.html">
    <FRAME NAME="Body" SRC="FRBody.html">
    <FRAME NAME="Footer" SRC="FRFooter.html">
</FRAMESET>
</HTML>
Figure 1: A Generic Multiframe Document

You will notice that there is no BODY tag within the document. A multiframe document should not have a BODY tag pair in the FRAMESET HTML file. This document above is divided into three rows. The percentages indicate how much of the browser window will constitute each of the rows. The first row is contained in a frame called 'Header' and the contents are kept in the file 'FRHead.html' and similarly for the second and third rows. You can also specify the size in a fixed number of pixels or just place an asterisk for one of the rows to indicate that that row will take up the rest of the space of the browser that is available. You can indicate a number of other options for frames but I won't go through all the details, that would require a whole article in itself. Instead, I direct you to the information at Netscape's site on FRAMEs and another tutorial on how to use them, listed at the end of this article.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources