The HTML language used to create pages for the World Wide Web was originally designed to produce plain and static documents -- stuff like engineering notes and long-winded arguments by scientist types. When the Web first started the only browsing software available for it was text-based, so "plain and static" was acceptable.
The Web took a major step with the release of Mosaic, the first graphical Web browser. Suddenly, it was obvious to most everyone that "plain and static" wasn't enough. Users cried out for more creative control over the pages they published on the Web, which ushered in such features as in-line images, tables, and frames.
program. A macro is small program designed solely to run inside a program, and automate some
task or to enhance a feature of the program. The difference here is that instead of a word
surfing on the World Wide Web.
At first, interest in LiveScript was mild, due mostly to the frenzy surrounding a more robust Internet programming language, named Java. Java was developed over a three year period at Sun Microsystems, a company long entrenched in the Internet. Programmers flocked to Java because of its potential, at first leaving LiveScript in the cold.
two dozen companies jumped on the bandwagon promising to support it for future products.
Those products -- from companies such as Microsoft, America Online, Borland, IBM, Symantec,
and many others -- are just now coming out, or will be released shortly.
Tailor Pages for the User
Make Interactive Pages
Oh, Yes -- And Special Effects, Too!
Possible uses: bar charts, colored divider lines (no more plain <HR> horizontal rules!), and more.
Consider the very basic HTML document. It renders a heading and some text on the page. Figure 1-3 shows how the page looks when viewed in Netscape.
<HTML> <HEAD> <TITLE>This Is a Basic Document</TITLE> </HEAD> <BODY> <H1>This Is a Basic Document</H1> <P>This is a pretty basic document. It doesn't have much of anything in it. Just a heading, and this text.</P> </BODY> </HTML>
<Figure 1-3. A basic HTML document, as rendered in Netscape.>
<HTML> <HEAD> <TITLE>This Is a Basic Document</TITLE> </HEAD> <BODY> <SCRIPT> document.write ("<H1>This Is a Basic Document</H1>"); </SCRIPT> <P>This is a pretty basic document. It doesn't have much of anything in it. Just a heading, this text, and a graphic of some line.</P> </BODY> </HTML>
Trying the Script Yourself
If you get an error box like that in Figure 1-5, it means you didn't properly type the text between the <SCRIPT> and </SCRIPT> tags. Carefully review your work and try again.
<Figure 1-4. The output results of the sample.htm document.>
The Role of the <SCRIPT> Tag
But these are not allowed:
the time of day:
<HTML> <HEAD> <TITLE>This Is a Basic Document</TITLE> </HEAD> <BODY> <H1>This Is a Basic Document</H1> <P>This is a pretty basic document. It doesn't have much of anything in it. Just a heading, this text, and a graphic of some line.</P> <SCRIPT> now = new Date(); if ((now.getHours() > 5) && (now.getHours()<18)) document.write ("<IMG SRC='http://mydoamin.com/day.gif'>"); else document.write ("<IMG SRC='http://mydomain.com/night.gif'>"); </SCRIPT> </BODY> </HTML>
You've probably heard of object oriented programming. It's a style of programming where software is created using self-contained modules. Each module is designed to take a certain type of data, and do something with it. The term "object oriented" comes from how the data is viewed: as an object. While object oriented programming is more difficult than the traditional "precedural" programming (like Basic and C), the end result is usually easier to maintain and fix. Almost all major software products released today are written using object oriented techniques.
These things -- er, objects -- are best viewed as a total entity to make programming easier. Objects are composed of properties, which is stuff that belongs to that object. As in real life, not all objects have the same properties. Imagine a window. That's an object. Now imagine that window having a property for open/closed (the one property can represent both states).
Now imagine the lamp by your desk. It's an object too, but it doesn't have an open/closed property. Instead, it has an on/off property. Each property is contextually relevant to its object. This is an important concept.
(in this case document), a period, and the property name, which is bgColor. Put 'em together and
document.bgColor = "black";
Test this for yourself Here's a short script that sets the background according to the time of day. It uses document.bgColor to set the background color, and fgColor to set the foreground (text) color. The page is rendered black-on-white for the daytime, and white-on-black for the nighttime. I'll use the color names for this example, rather than the #nnnnnn color triplet values you may be used to. Both are valid with Netscape.
A Method to Its Madness
Closely related to objects are methods. A method is something you can do with an object. Like properties, methods are contextually tied with the object they belong to, and not all objects have the same methods. Think of a method as an action that causes the object to change or respond in some way. Consider that window and desk lamp again. A valid method for the window might be to open and close it. A valid method for the lamp might be to turn it off an on.
happen to an object. There are dozens of methods, each one contextually related to the object it
Unlike methods, however, functions are unlike methods in that they are not intrinsically tied to an
Statements Tie It All Together
Comments are welcome
Copyright © 1996 Gordon McComb and
Revised: October 16, 1996