`
`Apple Inc. Exhibit 1022
`
`
`
`Apple Inc. Exhibit 1022
`
`Apple Inc. Exhibit 1022
`
`
`
`USING
`AVASCRIPT
`
`Written by Mark C. Reynolds with
`
`Ray Daly • Rick Darnell • Bill Dortch
`Mona Everett • Scott! Walter • Andrew Wooldridge
`
`Apple Inc. Exhibit 1022
`
`
`
`Special Edition Using JavaScript
`Copyright© 1996 by Que® Corporation.
`
`All rights reserved. Printed in the United States of America. No part
`of this book may be used or reproduced in any form or by any
`means, or stored in a database or retrieval system, without prior
`written permission of the publisher except in the case of brief quota(cid:173)
`tions embodied in critical articles and reviews. Making copies of any
`part of this book for any purpose other than your own personal use
`is a violation of United States copyright laws. For information, ad(cid:173)
`dress Que Corporation, 201 W. 103rd Street, Indianapolis, IN, 46290.
`You may reach Que's direct sales line by calling 1-800-428-5331.
`
`Library of Congress Catalog No.: 96-68041
`
`ISBN: 0-7897-0789-6
`
`This book is sold as is, without warranty of any kind, either express
`or implied, respecting the contents of this book, including but not
`limited to implied warranties for the book's quality, performance,
`merchantability, or fitness for any particular purpose. Neither Que
`Corporation nor its dealers or distributors shall be liable to the pur(cid:173)
`chaser or any other person or entity with respect to any liability,
`loss, or damage caused or alleged to have been caused directly or
`indirectly by this book.
`
`98 97 96
`
`6 5 4 3 2 1
`
`Interpretation of the printing code: the rightmost double-digit num(cid:173)
`ber is the year of the book's printing; the rightmost single-digit
`number, the number of the book's printing. For example, a printing
`code of 96-1 shows that the first printing of the book occurred in
`1996.
`
`All terms mentioned in this book that are known to be trademarks
`or service marks have been appropriately capitalized. Que cannot
`attest to the accuracy of this information. Use of a term in this book
`should not be regarded as affecting the validity of any trademark or
`service mark.
`
`Java and other Java-based names are trademarks of Sun
`Microsystems, Inc., and refer to Sun's family of Java-branded
`technologies.
`
`Screen reproductions in this book were created using Collage Plus
`from Inner Media, Inc., Hollis, NH.
`
`Apple Inc. Exhibit 1022
`
`
`
`CHAPTER
`
`See the vairous ways JavaScript is
`making more dynamic Web sites.
`Some are so good, you'll save
`them to use over and over again.
`
`- JavaScript on the Web
`- See how simple JavaScript
`- Java$cript.pages can also be
`gadgets, - Learn the difference between
`- Scripts make great
`
`pages can be
`You will see easy-to-implement
`code that lets you add entirely
`new features to your Web site.
`
`complex
`With JavaScript you can have
`interaction between frames and
`multiple windows. It's not just for
`
`JavaScrlpt and Java
`Though the two languages share
`the same :first name, they are very
`different. Don't mistake them for
`being the same.
`
`applications
`There is no :firm definition of a
`scripting language, An examina-
`tion of several can provide some
`insights to where you can go with
`JavaScript.
`
`What Is JavaScript?
`
`by Ray Daly
`
`Remember the thrill of visiting your first Web page
`and clicking your first hyperlink to another site?
`The excitement of surfing from California to
`Maine, from Australia to Finland? This interac(cid:173)
`tive nature of the Web attracts millions of people
`to the Web every day.
`
`With JavaScript, new dynamic elements let you
`go beyond the simple click and wait. Users will
`not just read your pages but also interact with
`them. Your pages come alive for any user, even
`with the slowest Internet connection. Users will
`get quick responses because the interaction does
`not need to involve the server but can take place
`in their browser.
`
`This interaction can change your pages into an
`application. Put together a few buttons, a text
`box, and some code to produce a calculator. Or
`an editor. Or a game. Or the "killer'' JavaScript
`application that everyone wants. Users will save
`your JavaScript enhanced pages to use your
`application again and again.
`
`Apple Inc. Exhibit 1022
`
`
`
`Chapter 1 What Is JavaScript?
`
`JavaScript is a programming language that allows scripting of events, objects, and
`actions to create Internet applications. II
`
`Live Content on the WWW
`
`In building Web pages, you present information to your audience. The design and
`layout should entice them to explore your site. Your hyperlinks provide several
`predefined, but different, paths to see your information.
`
`With J avaScript, your pages come alive! Your pages respond to the requests of
`your audience beyond a simple click here or there. Many more interactive ele(cid:173)
`ments are now available for exciting design and layout. Your users are no longer
`just readers. People will interact with your documents, not just read them. Your
`users can now interact with forms, change the look and feel of your Web docu(cid:173)
`ments, and use multiple windows.
`
`Forms Explode with Information
`With JavaScript, forms are a consideration in nearly every page you design. Text
`fields and textareas can dynamically change in response to user responses. Your
`audience will look for buttons, selections, radio buttons, and checkboxes. Your
`pages will change at their touch. The following examples show you how J avaScript
`makes forms come alive:
`
`II Calculators-Where is that calculator when you need it? On your page (see
`fig. 1.1). Beyond simple arithmetic, you can do conversions in hexadecimal,
`calories, metric, and more. Expand the form and you have the unlimited
`world of spreadsheets-for example, simple tax forms, grade-point averages,
`and survey analysis.
`
`II Display time. What time is it? It's easy to show in a basic text box (see fig.
`1.2). Or how about the time anywhere in the world? Add in a little math and
`show users the elapsed time. Different math produces a countdown time.
`A little different code and you have a population explosion or national debt
`counter.
`
`Apple Inc. Exhibit 1022
`
`
`
`Live Content on the WWW
`
`11
`
`FIG.1.1
`Calculator built in to a Web
`page with JavaScript.
`
`Elle
`
`fdlt ~lew §o
`
`.,
`)1ookmarks Qptlons
`
`Postfix Notation Calculator
`
`11lis calculator uses postfix notation, and works a little differently from calculators you may have
`used. Suppose you want to add two numbers. Enter the first number. Press "Enter." Ths commits
`the first number into the calculator's memory. Then enter the second number. After that, enter the
`type of operation (such as"+") that you wish to perform
`
`FIG.1.2
`JavaScript time displays
`usually show you the local
`time.
`
`ill Feedback status. As you build JavaScript applications, there will be a lot going
`on. Your code will have loops, increment variables, and track user inputs.
`Let the users in on what's going on. Provide feedback with a numeric counter
`(see fig. 1.3). Say it "graphically" with a bar graph made of ASCII characters
`and show a status literally.
`
`FIG.1.3
`Text boxes can feed back
`status of applications to
`users numerically, with
`ASCII graphics, or verbally,
`in text boxes.
`
`Apple Inc. Exhibit 1022
`
`
`
`Chapter 1 What Is JavaScript?
`
`111 Verification. With user input, you usually want to verify the validity of the
`response. For example, if you want the response to be a number between 1
`and 10, JavaScript can verify that the user's response falls in that range. If
`not, the code can notify the user and ask again for the input (see fig. 1.4).
`Once verified, the result is submitted to the server.
`
`FIG.1.4
`Provide your users with
`instant feedback without
`waiting for a response from
`the server.
`
`111 Entertainment. Everyone wants to have fun-even when learning. You can
`convey your information as an interactive game or even as a joke (see figs.
`1.5 and 1.6). The source code is very simple (see listing 1.1).
`
`FIG.1.5
`Punchline: now you see the
`joke without the punchline
`revealed.
`
`Punchline
`
`a javascript demo by Ray Daly
`
`Why did the chicken cross the road?
`
`Apple Inc. Exhibit 1022
`
`
`
`Live Content on the WWW
`
`13
`
`FIG.1.6
`Here's the punchline,
`hidden until you are ready
`to see it.
`
`The source code in listing 1.1 is easy to modify to tell your own jokes on the Web
`without giving away the punchline.
`
`Listing 1.1 javapnch.htm Code for JavaScript Punchline
`<HTML>
`<HEAD>
`<TITLE>javascript Punchline demo by Ray Daly</TITLE>
`<SCRIPT LANGUAGE="LiveScript">
`<!--
`hide this script from some browsers
`function Punchline () {
`document.write ("<BODY BGcolor=#00EE00><P>
`•<I>To get to the other side.</P></I>") ;
`
`}
`II hidden ray.daly@mailcall.com 12/16/95-->
`</SCRIPT>
`</HEAD>
`<BODY>
`<H1>Punchline</H1>
`<H2>a javascript Punchline demo by Ray Daly</H2>
`<P>Why did the chicken cross the road?</P>
`<FORM>
`<P><INPUT TYPE="button" VALUE="Punchline" onClick=Punchline()>
`</P>
`</FORM>
`</BODY>
`</HTML>
`
`Apple Inc. Exhibit 1022
`
`
`
`Chapter 1 What Is JavaScript?
`
`Look and Feel Is An Option
`All of the elements inside the window of a browser are available in JavaScript. You
`can dynamically change some of these elements. Or you can examine the elements
`of one document and use that information to create a different document. The
`following are some examples of changing the look and feel of documents:
`
`II! Change colors. Ever get to a page where the colors nearly make you go blind?
`Give your users a choice of several color combinations of backgrounds and
`text colors. As your application displays documents, use your users' colors
`(see fig. 1.7).
`
`There are too many colors for a user to choose. Don't make them experiment; let them
`select from some good combinations you have already tested.
`
`FIG.1.7
`Sample of menu where you
`can change the background
`color.
`
`A Backg•·ound Selector in JavaScript
`
`II! Change links. Normally, users click hyper links and off they go to the site you
`specified as the URL for the hyperlink. With JavaScript, this link can change
`based on user responses. If a user indicates a preference to baseball over
`football, your code can change the hyperlink to point to the Yankees instead
`of the Cowboys.
`
`Apple Inc. Exhibit 1022
`
`
`
`Live Content on the WWW
`
`15
`
`Reformat Pages. Since J avaScript can examine all of the elements of a docu(cid:173)
`ment, you can read a document in one frame and completely reformat it in
`another.
`
`An example is HTMLAnalysis (see fig. 1.8). In the control panel at the bottom of
`the window, you specify a URL that is displayed in the left frame. The right panel is
`generated from the code activated by the REDO button. This code reads the
`HTML code of the left document and creates an entirely new document that lists
`all of the hyper links. This new document is displayed in the right frame.
`
`Listing 1.2 shows the frames for HTML Analysis.
`
`Listing 1.2 hanalysl.htm Frames for HTML Analysis
`<HTML>
`<HEAD>
`<TITLE>HTML Analysis by Ray Daly</TITLE></HEAD>
`<FRAMESET ROWS="80,300,*">
`<FRAME SRC="hanalys1.htm" NAME="control">
`<FRAME SRC="" NAME="displayhere">
`<FRAME SRC="" NAME="analysis">
`<FRAME SRC="guide.htm" NAME="guide">
`</FRAMESET>
`</HTML>
`
`Listing 1.3 shows the code for HTML Analysis.
`
`Listing 1.3 hanalys1.htm Code for HTML Analysis
`<HTML>
`<HEAD>
`<TITLE>hanalys1.htm: part of hanalysi.htm</TITLE>
`<SCRIPT Lanuguage="JavaScript">
`function doit() {
`for (i = 0; i <parent.displayhere.document.links.length; i++) {
`parent.analysis.document.write (parent.displayhere.document.links[i]
`o. + "<BR>")
`
`}
`}</SCRIPT></HEAD>
`<BODY>
`<A HREF="http://www.cris.com/-raydaly/htmljive.html" TARGET="displayhere">
`Get a page.</A>
`<FORM><INPUT TYPE="button" VALUE="Probe it" onClick="doit()"></FORM>
`</BODY>
`</HTML>
`
`Apple Inc. Exhibit 1022
`
`
`
`Chapter 1 What Is JavaScript?
`
`CAUTION
`The HTML Analysis application is not stable on all platforms. Make sure the URL is completely
`loaded prior to doing the analysis.
`
`FIG.1.8
`The URL specified in the
`top frame is displayed in
`the second frame. The third
`frame shows only the links
`from that page. Such tools
`are a great way to make
`certain pages on your site
`meet your standards.
`
`Get a page
`
`HTMLjive Info
`
`~ HTHLjive was a JSI Link of the llo"ent (Jan.24.%)
`
`HTMLjive is a HTML editor written in Javascript. It allows an intermediate lnt
`create a HTML document by simply loading a Wob page, No other programs are n
`
`Demo of HTULj i ve
`You need a Javascript compatible brovser like Netscape 2. 0 to use this ed
`Uses of HTMlj i ve
`Describes how HiMLjive simplifies creating HTML documents, Also discusses
`·
`·
`·
`~.:.~lruBss.r.i.nt........,_
`
`http:/ h1v.rw. c2. Dl'g/ ...... andrei<nr/javascript/
`http: //,vr.nl. cris. com/Nraydaly/hjdeJw. shtml
`http://www. cris. com/"'raydaly/hjuses. shtll\l
`r11ail to: listserv@ro.ailcall. com
`http:/ /198. 2 32. 14 4. 18: 8080/$web,.sg. list. CO!!llEHTS. -12. 12
`riD
`.
`t
`'
`.
`'t'
`
`You can reformat pages for dramatic results. Instead of showing the entire document in a
`large frame, bring the source document into an extremely small frame. Then display your
`reformatted document in the much larger frame. If the frame with your source is small
`enough, your users won't even know what the original looked like.
`
`Tools for analysis. Analyzing tools are a very interesting derivative of refor(cid:173)
`matting documents. Instead of displaying a reformatted document, analyzing
`tools provide an analysis of a document. Tools could check such simple
`things as word counts, link counts, or other statistics. Code could even be
`written to show the tree structure of all of the objects in a document. Or you
`could write code to verify that pages meet the criteria for your corporate site.
`
`Apple Inc. Exhibit 1022
`
`
`
`Live Content on the WWW
`
`17
`
`Multiple Windows and Frames
`Netscape introduced frames and JavaScript with Navigator 2.0. You will probably
`also find yourself using another popular feature: opening multiple windows for
`browsing the Web. Microsoft Internet Explorer 3.0 also supports JavaScript,
`frames, and multiple windows. Add some J avaScript behind these new features and
`the browser becomes a kaleidoscope on the WWW. No longer are you limited to
`browsing one page at a time. Now you can view multiple documents and see a
`multifaceted view of the Internet world. The following list examines using multiple
`windows and frames:
`
`11 Alert, confirm, and prompt dialog boxes. JavaScript has its own built-in dialog
`boxes you can use in your design. Alert users to take caution (see fig. 1.9),
`confirm an action with an okay or cancel response (see fig. 1.10), or prompt
`for a text input (see fig. 1.11).
`
`FIG.1.9
`Alert box notifies the user,
`but provide no choices.
`
`FIG.1.10
`Confirm box notifies the
`user and allows him to
`cancel the action.
`
`FIG.1.11
`Prompt box lets the user
`type a response to your
`code.
`
`Ill Control windows. Beyond the built-in dialog boxes, you can create your own
`controls with custom windows. Populate them with buttons, text boxes, or
`icons to control the results in your other windows.
`
`Apple Inc. Exhibit 1022
`
`
`
`Chapter 1 What Is JavaScript?
`
`II Navigation windows. Have two, three, or more windows all opened simulta(cid:173)
`neously. As the user navigates from one, the others display various screens of
`information. For example, each window might pull in a live image from a
`different point around the globe as selected by the user. Internet Tri-Eye
`provides live views from around the world (see fig. 1.12).
`
`FIG.1.12
`Internet Tri-Eye is an
`example of a multi-window
`application and a control
`panel. Selections in one
`frame produce results in
`other frames.
`
`Eye One
`
`Eye Two
`
`Eye Three
`
`Tri-Eye Guide
`
`Desc•1ptive infonnation about the images in the 'Eyes' will be placed here and below.
`
`Interact with Other Live Objects
`Sun Micro systems and N etscape Communications introduced J avaScript. An addi(cid:173)
`tional28leading computer companies, including AOL, AT&T, Borland, Digital
`Equipment Corporation, Hewlett-Packard Corporation, and Oracle Corporation
`endorsed JavaScript. Microsoft supports JavaScript in Internet Explorer 3.0. These
`companies support JavaScript because it is an open standard object language. Sev(cid:173)
`eral companies will introduce products that incorporate J avaScript. This will allow
`even more interaction. The following products supportJavaScript:
`
`II Netscape's Live Wire. Live Wire is a visual development environment for
`creating Internet applications. This new product provides enhancements to a
`server including JavaScript. The same language that you use to make your
`pages come alive on the browser can be used to respond to requests at the
`server. Instead of writing CGI scripts in Perl, C, or some other language, use
`J avaScript.
`
`Apple Inc. Exhibit 1022
`
`
`
`Role of Scripting
`
`19
`
`1M Plug-ins. Plug-ins are software that work with Netscape's Navigator. Third(cid:173)
`party publishers such as Adobe, MacroMedia, Borland, and many others
`produce these applications. This software will allow viewing of other file
`formats, multimedia presentations, and specialized functions.
`
`N 0 r E For more information on plug-ins, visit this site: http:/ /home.netscape.com/
`com prod/ products/ navigator jversion_2 .0 I plugins/.
`The number of plug-ins for browsers is expected to grow astronomically. As
`these applications become more sophisticated, they are expected to use
`JavaScript as their scripting language. In addition, many of these publishers
`will allow JavaScript in the browser to interact with their plug-ins. The objects
`in this software will be available or exposed to JavaScript.
`
`N o r E Microsoft is actively promoting its scripting language VBScript. The primary
`function of this language is to interact with and create external applications.
`Because this language is a subset of Microsoft's Visual Basic and works with ActiveX
`controls, it is expected to have a substantial impact.
`
`Netscape Navigator 2.0 supports a new functionality-enhancing feature that
`provides inline support for a huge range of Live Objects. With Live Objects,
`developers can deliver rich multimedia content through Internet sites,
`allowing users to seamlessly view that content with plug-ins such as Adobe
`Acrobat, Apple QuickTime, and Macromedia Shockwave for Director in the
`client window-all without launching any external helper applications.
`II New Internet Products. Given the scope of the companies behindJavaScript,
`you can expect to see some very specialized Internet products. Many of
`these products will use JavaScript for customizing.
`
`Role of Scripting
`
`There is no definitive definition of a scripting language. Sometimes the term is
`used to make a distinction from compiled languages. However, some languages
`like C or C++ can be used for scripting as well as full applications. The term script(cid:173)
`ing is also used because a language will react to, control, or "script" a series of
`
`Apple Inc. Exhibit 1022
`
`
`
`Chapter 1 What Is JavaScript?
`
`events. Even macro languages built into PC applications like spreadsheets, data(cid:173)
`bases, word processors, and multimedia applications are now often called scripting
`languages.
`
`The purpose of most scripting languages is to extend the capabilities of applica(cid:173)
`tions. Just as the authors of this book cannot imagine every creative use you will
`make of J avaScript, software authors cannot imagine every possible use of their
`applications. To make their products more versatile, they add a scripting language.
`With JavaScript you have a scripting language to use your imagination on the Web.
`
`Current uses of scripting languages may give you an insight of the potential for
`JavaScript. You probably know that macros are built in to many PC applications.
`Apple's HyperCard contains a very powerful scripting feature. Perl is a scripting
`language used in many CGI scripts you use on the Web.
`
`PC Macros Become Scripts
`Traditionally, a macro feature was added to PC software to allow a simple series of
`commands to be executed with a single keystroke. With great fanfare publishers
`introduced this feature as a way to reduce repetitive tasks and save time. For
`example, a word processor's simple macro might change the entire style of a
`document.
`
`Over time the macro feature of various applications became complex scripting
`languages. As scripts became longer and nontrivial, they extended the software
`beyond its normal purpose. New and creative combinations of commands made
`the software the basis for entirely new applications-for example, a set of word
`processing scripts for maintaining a small mailing list.
`
`These scripting languages in software are so sophisticated that they are the sub(cid:173)
`ject of college courses. Many universities now require courses in spreadsheet
`scripting for accounting and business students. Art majors are learning scripting
`procedures for high-end graphics and multimedia packages. Legal courses include
`using scripts to create documents. And computer science majors have a variety of
`courses involving scripting languages.
`
`A defining factor of this type of scripting language is that they only work with appli(cid:173)
`cations. Scripts in word processors add word processing features. Scripts in
`spreadsheets add spreadsheet features. These scripts do not go beyond the nature
`
`Apple Inc. Exhibit 1022
`
`
`
`Role of Scripting
`
`21
`
`of the software, but they use the existing commands of the software. In our ex(cid:173)
`ample, the mailing list script still works with words, the standard element of the
`word processor. This becomes a limitation on the usefulness of this script.
`
`With the popularity of program suites like Microsoft Office, Lotus SmartSuites,
`and Perfect Office, PC publishers have started making the same scripting lan(cid:173)
`guage work with more than one application. (Some would say that, at this point,
`macro languages become scripting languages.) Not only is the same language
`used in each application, the script language helps the applications work together.
`Microsoft expanded the role of Visual Basic to work with Microsoft Access and
`Excel. Lotus has developed LiveBasic for its product suite.
`
`With the PC environment, the role of scripting languages is serious business. It's
`the subject of college courses and often used to build nontrivial applications.
`
`N 0 r E Historically, scripting has made several "killer applications:· These are
`applications, that define a whole new category of software, significantly
`expand the market, and provide a primary reason for people to use a computer. The first
`successful spreadsheet was VisiCalc, which disappeared with the success of Lotus 1-2-3.
`The latter had scripting. There were many different database applications on the market
`before Ashton-Tate's dBase, but this product was programmable with a scripting
`language.
`
`Scripting gave these applications a competitive edge. First, it was a feature that could be
`used to sell the product. Second, people actually started to use the feature and create
`significant new capabilities for these products. Third, these scripts created a whole new
`market with magazine articles, books, third-party software publishers, and training.
`Fourth, the continuing use of these scripts became an investment by the user in these
`products. Existing scripts often prevented users from switching to competitive products.
`And finally, even when a competitive product was introduced with new features, someone
`would introduce scripts that attempted to add these features into the existing products.
`Scripts allowed both the publisher and users to advance.
`
`Scripting in Macintosh Applications
`The most notable use of scripting on the Macintosh is Apple's HyperCard pro(cid:173)
`gram. This application lets you build a group of cards and hyper link them together.
`The cards can contain not only text but multimedia files. The stack of cards that
`you construct can respond to user input.
`
`Apple Inc. Exhibit 1022
`
`
`
`Chapter 1 What Is JavaScript?
`
`The scripting language is such a strong element of HyperCard that many people
`consider HyperCard itself to be a language. Many Mac owners were initially disap(cid:173)
`pointed with HTML because it lacked many of the capabilities of HyperCard. In
`many ways, J avaScript brings some of the HyperCard features to the Web.
`
`Perl Started as a UNIX Scripting Language
`If you have used the Web, you have used Perl. It is the language used for probably
`the majority of CGI scripts. These are routines that run on Internet servers and
`respond to requests from browsers when a user completes a form. There are
`guestbooks, message boards, voting pages, surveys, and more that use Perl
`scripts.
`
`Perl is an interpreted language. While you should be able to find a version of Perl
`for almost any computer platform, it was created for UNIX systems. It is now plat(cid:173)
`form independent. The vast majority of Perl scripts will run without modification
`on any system. Take a script written on UNIX and it will run perfectly well on
`DOS.
`
`A CGI script is a type of script that responds to events. In this case, the event is
`a user submitting data from an HTML form. The attributes of a <FORM> include
`ACTION, which defines the script to process the data when it is submitted. For
`example,
`
`<FORM ACTION='\cgi-bin\guestbook.pl'>
`
`will process the data from the form in a script called guest book. pl. More than
`likely this routine would store the data in a file and return an HTML page to the
`browser as feedback. It would probably say something like, ''Thanks for your entry
`into our guestbook."
`
`Perl is freely distributed on the Internet, but please see its license for more detail.
`You should be able to find a version for your system using any of the Internet
`search services. Larry Wall is the sole maintainer.
`
`Perl's strength as a language is in manipulating files and text to produce reports.
`This capability along with its associative arrays make it a natural fit for creating
`CGI scripts. In a few lines you can process data and return an HTML document in
`response to an HTML form.
`
`Apple Inc. Exhibit 1022
`
`
`
`Extend the Capabilities of the HTM L Page
`
`23
`
`If you are a Perl programmer, you can rather quickly learn JavaScript. Both have
`a similar control structure and both are interpreted languages. Unlike Perl,
`JavaScript is object-based but it is not nearly as complex. You might miss the text
`processing capabilities of Perl, but you will find J avaScript a delightful new lan(cid:173)
`guage to learn.
`
`There are some cases where JavaScript is not the appropriate solution, but using
`Perl for a CGI script would fit the requirement. Generally, if you need to store in(cid:173)
`formation, you are going to have to do that on the server and Perl would be a good
`choice.
`
`Extend the Capabilities of the HTML Page
`
`Like other scripting languages that extend the capabilities of the application with
`which they work, JavaScript extends the standard Web page beyond its normal
`use. You have already seen in this chapter numerous ways to make your Web site
`come alive. And given the flexibility of the language, the only limit is your imagina(cid:173)
`tion. We must now consider how JavaScript works within HTML pages.
`
`JavaScript Pages Work Differently
`With the standard Web site, you get more information by clicking a hypertext link
`and having the server send you another file. On a more interactive page, you com(cid:173)
`plete a form, submit the results to the server, and wait for a response. In either
`case you must wait on the server to send a new file. This information is almost
`always a new page, though it might be a multimedia file like an audio clip or an
`animation.
`
`With JavaScript-enhanced pages, there is JavaScript code embedded in the HTML
`code. The JavaScript can instantly provide you information without waiting on the
`server or your Internet connection (see fig. 1.13). This information can come from
`user input, code "hidden" with the document, or other documents in frames or
`other windows.
`
`Apple Inc. Exhibit 1022
`
`
`
`Chapter 1 What Is JavaScript?
`
`This JavaScript-enhanced page makes this new information visible by updating the
`contents of a form or by generating an entirely new document. In a J avaScript cal(cid:173)
`culator (refer to fig. 1.1), the form is updated when numbers are entered. In the
`Punchline script (refer to fig. 1.5), the user clicks the button and a new document
`is created from the hidden punchline of the joke.
`
`FIG.1.13
`With standard HTML pages,
`a Web site serves each
`page to the browser. With
`JavaScript-enhanced pages,
`the source for a page can
`be the existing page.
`
`Server
`
`Server
`
`Page 3
`
`Each new page is sent in response to
`a request of the server
`
`The page with JavaScript can produce a
`new page without making a request to the
`server
`
`JavaScript Meets the HTML Page
`J avaScript works with browsers by embedding code directly into an HTML page.
`Netscape added a new generic tag called SCRIPT to recognize scripting languages.
`To inform the browser that your code is JavaScript, you must add the attribute of
`LANGUAGE="Javascript" to the SCRIPT tag. Much of your JavaScript coding is en(cid:173)
`closed within these tags, as you can see in the following example:
`
`<SCRIPT LANGUAGE="JavaScript">
`a = "Hello!"
`// ... set a variable called 'a' to a value of "Hello!"
`</SCRIPT>
`
`N o T E Like most any other computer language, JavaScript allows you to place
`comments within your code. Single-line and multiple-line comments are
`possible. A multiple line starts with the two characters 1 *. It ends with the two charac(cid:173)
`ters * 1.
`
`Consider the following example:
`/* This is the start of multiple lines of comments.
`This is the end */
`To make a comment at the end of a line or on a single line, just use the characters 11
`and everything after that mark until the end of the line will be considered a comment.
`
`Apple Inc. Exhibit 1022
`
`
`
`Extend the Capabilities of the HTM L Page
`
`25
`
`Between sCRIPT tags you can write two types of code: direct statements and jUnc(cid:173)
`tions. Direct statements are executed by the browser as they are loaded. For ex(cid:173)
`ample, objects are initialized in direct statements. Functions are blocks of code
`that are executed only by other code or events.
`;. See chapter 3, "Events and JavaScript," for more information about code and
`events, p. 75.
`
`For example, mouse-click events usually trigger functions. Most of your programs
`will use both direct statements and functions.
`
`Many existing HTML tags now have additional attributes to support J avaScript.
`For example, all elements of a form can now be identified with the NAME element.
`You should be familiar with the NAME attribute because it has long been used in
`creating anchors. Using NAME to identify objects in your documents will generally
`simplify your coding and debugging.
`
`The final addition to HTML is recognizing events like mouse clicks, changes in
`text boxes, and the loading or unloading of pages. This is how the document rec(cid:173)
`ognizes the user interaction. These events are used to trigger JavaScript actions.
`The code can be quite straightforward, as in the following:
`
`<FORM>
`<P>Click inside the box and then out to see change.
`<INPUT TYPE="text" NAME="sample" onChange = "sample.value = a">
`<!--
`... after any change in this text box, but the value of a in
`.,..the box - ->
`</FORM>
`
`The J avaScript code that is triggered by an event can be simple or complex. With
`simple actions, the entire code can be placed in the event element. This is shown
`in the previous example with sample. value = a. Throughout this book you will see
`more typical examples of where functions are called by events.
`
`Limited by Objects in the Browser
`Like any language, J avaScript manipulates data. Being an object-based language,
`there are methods and jUnctions that act on the data in the objects. Other than
`string, math, and date objects, JavaScript is limited to operating on browser objects
`and other objects exposed to the browser. These other objects can include plug(cid:173)
`ins, Java applets, and ActiveX. This allows you to create new documents, modify
`your existing forms, and build applications.
`
`Apple Inc. Exhibit 1022
`
`
`
`.-·--------.
`26
`
`Chapter 1 What Is JavaScript?
`
`JavaScript works with browser objects, wh