Chapter 1
Coffee? In My Computer? I Prefer Decaf...

In This Chapter

Extending the Web

In the "old days" of the World Wide Web (three whole years ago), there were two ways to get information (also called content) to the user. The primary way was through HTML (HyperText Markup Language), the language used to write Web pages. HTML enables you to present text and 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.2), 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 these capabilities, 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 and that the server runs in response to something inside the Web page. With CGI, you can:

An image on the image map

Which part of an image you click determines what happens next.

Pushy Servers The technical term for CGI "flip-book" animation is server push.It's so named because 
the CGI program instructs the server to send (or "push") one graphic after another to the browser. 
Conversely, you could also use CGI to instruct the browser to "pull" one graphic after another from the 
server. This technique is (not surprisingly) called client pull.
 
  • Interface with a database on the server to retrieve or add information. Online  catalog ordering uses
      CGI, as well as the earch engines (such as Yahoo,  Lycos, and WebCrawler) that keep track 
     of everything there is to find on the Web
  •  
    One disadvantage of CGI is that you must be a programmer to use it. Secondly, C GI 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 the 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 offer a Web server w ith incomplete CGI tools or with none at all. In 
    addition, multimedia (sound, graphics, animation) has become all the rage, and everything in c omputers 
    today has to support multimedia.  CGI doesn’t do this well.
     
     

    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 root, and the Perl language is a UNIX-based language. However, a CGI program 
    can be written in any language that the Web server supports.

    Finally, to use CGI, you must have access to the CGI interface of the Web server that’s serving up your pages. As I’ve 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 doesn’t support all of the visually fancy things authors want to include in their pages. But 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, was designed to allow more power and flexibility for the presentation of material on the Web. With Java, you can...

    Java works the floor in 3D rotating glory.

    Before Java, if you wanted to view a graphic, play a movie, or listen to a sound file on the Web, you had to have a helper application (an independent program unrelated to the browser) installed on your computer and connected to your 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 more helper applications, and no more CGI programming. All you need is a Java-enabled browser to view Java programs, and the Java Developers Kit to design them (it’s available for free 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 also 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 (by a compiler) before you can use them. A compiler is a special program that reads your own program and crunches it into machine-readable binary code. In spite of the existence of several nice development packages for building Java applets, compilers can be a hassle because you have to use them every time you make a change to your program, and it can take a long time to compile a program.

    Scrolling ticker tape Scrolling ticker tapes—trust me; they scroll.

    So what you need is a way of getting the capability of Java without the added baggage of a full-blown programming language. Well, this time, Netscape comes to the rescue (with a little help from Sun) with JavaScript.

    Enter JavaScript

    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 experienced programmers. 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, but that would require 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). To help the marketability of their new language, Netscape paired up with Sun, and JavaScript was born.

    In theory, JavaScript is available for free to those who design Web browsers; this enables the designers to incorporate JavaScript compatibility into their browsers. In reality, Microsoft was the first to implement a version of JavaScript (which they named JScript), but they did not refer to the official JavaScript specifications. Thus, Microsoft Internet Explorer 3.0 is “mostly” JavaScript-compatible, but it’s not 100% (I explain this issue in more detail in Chapter 2).

    Recently, Netscape handed JavaScript over to an independent standards organization with the hope that all potential developers of Web browsers will have equal access to the official JavaScript implementation. As a result, hopefully, Internet Explorer 4.0 (due out sometime in the spring of 1997) will support JavaScript better than version 3.0 does. 

    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 capability to extend or change how t
    heir program behaves through a script.

    A script is 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 (though 
    there are many more). Some examples of stand-alone scripting languages are Perl and REXX.

    Scripting languages make extending these packages easy. (And you don’t have to be a programmer, 
    purchase an expensive compiler, learn some strange pseudo-English language, or start wearing plaid 
    shirts and pocket protectors.)

    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.

    Thinking of Objects 

    Like Java, JavaScript is built on the concept of objects. Unlike Java, however, JavaScript provides a basic collection of objects for you to work with. While you can easily create new objects and object types, the ones provided give you a great deal of power.

    As the word implies, an object is a thing—any thing. I don’t mean to sound vague, but the term object is used to generically group a collection of different “blocks of stuff” together. In the world of computers, objects are different pieces (or building blocks) that make up a computer system or program. Objects shield 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 (which is called “setting an object's properties”), and the black box does something in response. Actually how it works isn’t important, just that it does work. This is the basis for the concept of object-oriented programming, in which 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,” we could change the color of the computer screen by telling the screen object to set it’s color property to, say, green. Whether the computer is a Macintosh or an IBM PC, the object would do the same thing.

    In Chapter 5, you begin an up-close and personal look at objects in their natural habitat.

    The Least You Need to Know

    In this chapter, you took a quick look at the origin of JavaScript. 

    Next Chapter

    Beginning of ChapterTable of ContentsQue Home Page


    For comments or technical support for our books and software, select Talk to Us.


    Copyright © 1997, QUE Corporation, an imprint of Macmillan Publishing USA, a Simon and Schuster Company.