Que Logo

Chapter 2

Coffee? In My Computer? I Prefer Decaf…



In This Chapter

Extending the Web


In the "old days" of the World Wide Web (two whole years ago), there were two ways to get information (also called content) to the user. The primary one was through HTML or HyperText Markup Language, the language used to write Web pages. HTML allows for presenting text and displaying certain types of graphics, as well as links to connect one page to another page-either on the same computer or somewhere else in the world. As HTML has evolved (the current standard being worked on is version 3.0), other features have been added such as forms, frames, tables, and so on. However, even with all the new features, HTML basically deals with Web content by
Although this provides a wealth of possibilities for content manipulation (just spend a little time on the Web to see for yourself), it doesn't allow for more advanced things like accessing a database, ordering catalog items online, or making animated graphics within a Web page. For this, you need to understand the Common Gateway Interface, or CGI.
CGI provides a means of extending the capabilities of HTML by allowing the Web designer to write custom programs that interact with Web pages to do more complex things. A CGI program is a file that resides on the Web server that the server runs in response to something inside the Web page. With it, you can…

An image map; clicking on different parts of this image determines what happens next. You used to have to know CGI programming to create one of these.



Most CGI Programs Are Written in Perl

Because the Internet originated within the UNIX world (before Windows computers or Macintoshes were hooked up to it), much of what drives the Internet (and the Web) is based in UNIX. CGI stems from this same basis, and the Perl language is a UNIX-based language. But, a CGI program can be written in any language that the Web server supports.
The downside of CGI is you must be a programmer to use it. Secondly, CGI requires that the user's actions be reported back to the server for interpretation and processing. The results of this processing then must be sent back to the user from this server. These extra transfers take time and reduce the "immediacy" of certain Web page interactions. Furthermore, you are limited to the CGI capabilities of your server-your provider might not offer a Web server with complete CGI tools, or any at all. Also, multimedia (sound, graphics, animation) has become all the rage, and everything in computers today has to have or support multimedia. CGI doesn't do this well.
Finally, to use CGI, you must have access to the CGI interface of the Web server that's serving up your pages. As mentioned, some providers might not support CGI access, or it might be offered for an extra (in many cases, costly) fee.
In other words, CGI is more complex than most Web authors are interested in, and it doesn't support all of the visually fancy things authors want to include in their pages. Something else is necessary, and that something is Java.

Java: Web Programming for the Common Man


You can't surf the Web today without hearing about Java. Java, a programming language developed by Sun Microsystems, is designed to bring more power and flexibility to the presentation of material through the Web. With Java, you can…
Before Java, if you wanted to view a graphic, play a movie, or listen to a sound file on the Web, you needed a helper application installed on your computer and connected to your browser (an independent program unrelated to the browser). Whenever a particular file (movie, sound, or whatever) was retrieved from the Web, the helper would be run to display or play back the file. If you didn't have the necessary helper, you had to find it, download it, and install it.
Java handles these things internally. No helper applications. No CGI programming. All you need is a Java-enabled browser and the Java Developers Kit (freely available from Sun's Java Home Site, http://java.sun.com). And, as an added bonus, the Java programs you create (called applets or mini-applications) will run on any Java-enabled browser on any platform: Macintosh, Windows, or UNIX. You don't need to create a program for each machine type. One size fits all.
However, Java is not without its problems. It is a programming language and, as with all programming languages, you must learn it relatively well in order to use it. The applets you create must be compiled before you can use them. A compiler is a special program that reads your own program and crunches it into machine-readable binary code. Compilers can be a hassle, because you have to use them every time you make a change to your program, and they can take a long time to compile a program. Currently, there aren't any nice programming editor/compiler packages available that allow you to easily build Java applets, although several are being developed.
So, what you need is a way of getting the capability of Java without the added baggage of a full-blown programming language. Once again, Sun comes to the rescue (with help from Netscape) with JavaScript.

Enter JavaScript



What's a Scripting Language?

It's impossible for a computer program to be all things to all people. Software publishers try their best to make sure their programs can handle most of what users want, but they can never anticipate everything. To make their programs more flexible, many provide the ability to extend or change how their program behaves through a script.
Scripts are nothing more than a sequence of program instructions (called statements). The program steps through the statements one at a time and performs whatever the script tells it. This is exactly the same as "programming," except that scripts tend to have simpler rules and require less learning time. Some examples of programs that provide scripting are dBASE, Paradox, and Microsoft Access (although there are many more). Some examples of stand-alone scripting languages are Perl and REXX.
Script languages make extending these packages easy. You don't have to be a programmer, purchase an expensive compiler, learn some strange, pseudo-English language, and start wearing plaid shirts with pocket protectors.
JavaScript is a scripting language specifically designed to work with the World Wide Web. With JavaScript, you can take the power of HTML and the World Wide Web and extend it in a variety of ways.
Once upon a time (not too long ago), Sun Microsystems conjured up the complex and powerful programming language now known as Java. Although Java is highly capable, it's best suited for more complex tasks, and to be programmed by experienced users. Netscape Communications saw the need for an in-between language-one that would allow individuals to design Web pages that could interact with the user, or with Java applets, with a minimum of programming experience. Always one to be first on the block, Netscape whipped up LiveScript.
LiveScript was more of a proposal than an actual language, but it convinced people that this "bridge-the-gap" idea was attractive. LiveScript was designed in the spirit of many simple scripting languages, but tailored with capabilities specifically designed for Web pages (HTML and form interaction, for example). Sun Microsystems decided to get in on the act, and Sun and Netscape held hands and announced the newly named JavaScript.

What's an Object?

Like the word implies, an object is a thing-any thing. The term object is used to generically group a collection of different things together. In the world of computers, objects are different pieces (or building blocks) that make up a computer system or program. Using objects shields a programmer (or a JavaScript writer) from having to understand how the operating system works.
You can think of objects as little black boxes. You poke things into it (called setting properties) and in response, the black box does something. Actually how it works isn't important, just that it works. This is the basis for the concept of object-oriented programming, where the programmer is more concerned with what an object is doing than how it gets the job done.
For example, if you had a "screen object," you could change the color of the computer screen by telling the screen object to set its color property to, say, green. Whether the computer is a Macintosh or an IBM PC, the object would do the same thing (although in different ways).
In Chapter 6, you begin an up-close and personal look at objects in their natural habitat.
JavaScript is freely available for licensing, so that anyone who designs a Web browser
may implement it. The idea behind this is to make JavaScript a programming standard. Although Netscape Navigator is the first (and the only, at this writing) browser that supports JavaScript, the above licensing means that there will likely be others.
Based on Java, JavaScript supports most of Java's expression constructs (another word for statements). However, JavaScript doesn't require a compiler or a knowledge of programming to get up and running. All you really need is an understanding of HTML and a little logic.
Like Java, JavaScript is built on the concept of objects. Unlike Java, JavaScript provides a basic collection of objects for you to work with. You can't create new objects or object types, but the ones provided give you a great deal of power.

The Least You Need To Know


In this chapter, you took a quick look at the origin of JavaScript. You learned how the World Wide Web got its start through HTML, and how HTML was extended and enhanced through CGI programming. You discovered that Java came into being to satisfy the need to do more through the Web than either HTML or CGI could provide. Finally, you learned that JavaScript took Java one step further by making the same power of Java available to Web authors who don't want to learn how to program.
Now, it's time to start jivin' with JavaScript. But first, you need a browser that supports (can understand the commands of) JavaScript. Currently, the only browser that provides JavaScript power is Netscape Navigator 2.0. In the next chapter, you take a tour through the latest version of the most popular browser on the Web.

Previous Chapter

Next Chapter


Beginning of ChapterTable of ContentsBook Home PageQue Home Page


For comments or technical support for our books and software, select Talk to Us.
To order books, call us at 800-716-0044 or 317-228-4366.

© 1996, QUE Corporation, an imprint of Macmillan Publishing USA, a Simon & Schuster Company.