`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Mastering™ JavaScript
`
`James Jaworski
`
`San Francisco • Paris • Diisseldorf • Soest
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Associate Publisher: Gary Masters
`Acquisitions Manager: Kristine Plachy
`Acquisitions & Developmental Editor: Dan Brodnitz
`Editor: Doug Robert
`Book Designer: Catalin Dulfu
`Graphic Illustrator: Inbar Berman
`Desktop Publisher: Maureen Forys
`Production Coordinator: Anton Reut
`Proofreader: Theresa Gonzalez
`Indexer: Ted Lau x
`Cover Designer: Design Site
`Cover Illustrator: Design Site
`
`Screen reproductions produced with Collage Complete.
`Collage Complete is a trademark of Inner Media Inc.
`SYBEX is a registered trademark of SYBEX Inc.
`Mastering is a trademark of SYBEX Inc.
`
`TRADEMARKS: SYBEX has attempted throughout this book to distinguish proprietary trademarks from descriptive terms by following the
`capitalization style used by the manufacturer.
`
`Netscape Communications, the Netscape Communications logo, Netscape, and Netscape Navigator are trademarks of Netscape Communi(cid:173)
`cations Corporation.
`
`The author and publisher have made their best efforts to prepare this book, and the content is based upon final release software whenever
`possible. Portions of the manuscript may be based upon pre-release versions supplied by software manufacturer(s). The author and the
`publisher make no representation or warranties of any kind with regard to the completeness or accuracy of the contEints herein and accept
`no liability of any kind including but not limited to performance, merchantability, fitness for any particular purpose, or any losses or dam(cid:173)
`ages of any kind caused or alleged to be caused directly or indirectly from this book.
`
`Photographs and illustrations used in this book have been downloaded from publicly accessible file archives and are used in this book for
`news reportage purposes only to demonstrate the variety of graphics resources available via electronic access. Text and images available
`over the Internet may be subject to copyright and other rights owned by third parties. Online availability of text and images does not imply
`that they may be reused without the permission of rights holders, although the Copyright Act does permit certain unauthorized reuse as
`fair use under 17 U.S.C. Section 107.
`
`Copyright ©1997 SYBEX Inc., 1151 Marina Village Parkway, Alameda, CA 94501. World rights reserved. No part of this publication may be
`stored in a retrieval system, transmitted, or reproduced in any way, including but not limited to photocopy, photograph, magnetic or other
`record, without the prior agreement and written permission of the publisher.
`
`Library of Congress Card Number: 96-71650
`ISBN: 0-7821-2014-8
`
`Manufactured in the United States of America
`
`10 9 8 7 6 5 43
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Associate Publisher: Gary Masters
`Acquisitions Manager: Kristine Plachy
`Acquisitions & Developmental Editor: Dan Brodnitz
`Editor: Doug Robert
`Book Designer: Catalin Dulfu
`Graphic Illustrator: Inbar Berman
`Desktop Publisher: Maureen Forys
`Production Coordinator: Anton Reul
`Proofreader: Theresa Gonzalez
`Indexer: Ted Laux
`Cover Designer: Design Site
`Cover Illustrator: Design Site
`
`Screen reproductions produced with Collage Complete.
`Collage Complete is a trademark of Inner Media Inc.
`SYBEX is a registered trademark of SYBEX Inc.
`Mastering is a trademark of SYBEX Inc.
`
`TRADEMARKS: SYBEX has attempted throughout this book to distinguish proprietary trademarks from descriptive terms by following the
`capitalization style used by the manufacturer.
`
`Netscape Communications, the Netscape Communications logo, Netscape, and Netscape Navigator are trademarks of Netscape Communi(cid:173)
`cations Corporation.
`
`The author and publisher have made their best efforts to prepare this book, and the content is based upon final release software whenever
`possible. Portions of the manuscript may be based upon pre-release versions supplied by software manufacturer(s). The author and the
`publisher make no representation or warranties of any kind with regard to the completeness or accuracy of the contents herein and accept
`no liability of any kind including but not limited to performance, merchantability, fitness for any particular purpose, or any losses or dam(cid:173)
`ages of any kind caused or alleged to be caused directly or indirectly from this book.
`
`Photographs and illustrations used in this book have been downloaded from publicly accessible file archives and are used in this book for
`news reportage purposes only to demonstrate the variety of graphics resources available via electronic access. Text and images available
`over the Internet may be subject to copyright and other rights owned by third parties. Online availability of text and images does not imply
`that they may be reused without the permission of rights holders, although the Copyright Act does permit certain unauthorized reuse as
`fair use under 17 U.S.C. Section 107.
`
`Copyright ©1997 SYBEX Inc., 1151 Marina Village Parkway, Alameda, CA 94501. World rights reserved. No part of this publication may be
`stored in a retrieval system, transmitted, or reproduced in any way, including but not limited to photocopy, photograph, magnetic or other
`record, without the prior agreement and written permission of the publisher.
`
`Library of Congress Card Number: 96-71650
`ISBN: 0-7821-2014-8
`
`Manufactured in the United States of America
`
`109876543
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`TABLE Of CONTENTS
`
`Introduction
`
`IHHM Getting Started with JavaScript
`
`1 Fundamentals
`The Web
`The Hypertext Markup Language
`The Development of HTML
`Helper Applications
`External Viewers and Plug-Ins
`Using MIME Types to Identify Helpers for File Formats
`Universal Resource Locators
`The Hypertext Transfer Protocol
`Common Gateway Interface Programs
`Java Applets
`A Brief History of JavaScript
`Live Wire
`Intranets, Extranets, and Distributed Applications
`Summary
`
`2
`
`Introduction to JavaScript
`JavaScript and Browsers, JavaScript and Servers
`Embedding JavaScript in HTML
`Telling Non-JavaScript Browsers to Ignore Your Code
`The Noscript Tag
`The Script Tag's SRC Attribute
`JavaScript Entities
`JavaScript Comments
`Use of the Document Head
`Generating HTML
`Variables
`Types and Variables
`Types and Literal Values
`
`xxix
`
`5
`7
`9
`12
`13
`13
`14
`15
`17
`18
`19
`19
`20
`21
`22
`
`25
`26
`32
`34
`36
`38
`40
`40
`42
`45
`47
`47
`48
`
`xiii
`
`I
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Table of Contents
`
`Conversion between Types
`Complex Types
`Objects and the length Property
`Summary
`
`3 Operators, Statements, and Functions
`Operators and Expressions
`Arithmetic Operators
`Logical Operators
`Comparison Operators
`String Operators
`Bit Manipulation Operators
`Assignment Operators
`Conditional Expressions
`Operator Summary Table
`Operator Precedence
`Statements
`Assignment Statements
`Data Declarations
`The If Statement
`Loop Statements
`The Do While Statement
`Function Calls
`Local Variable Declarations
`The Return Statement
`Object-Access Statements
`The With Statement
`The For In Statement
`The Switch Statement
`Summary
`
`4 Event Handling
`What Are Events?
`How JavaScript Handles Events
`Handling JavaScript Events
`Handling Link Events
`Handling Window Events
`Handling Image Events
`Handling Image Map Events
`Handling Form Events
`
`57
`66
`73
`73
`75
`76
`77
`77
`77
`79
`79
`80
`81
`81
`87
`88
`90
`91
`92
`93
`94
`100
`104
`106
`107
`108
`109
`110
`111
`
`113
`114
`115
`121
`124
`128
`134
`137
`142
`
`xiv
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Setting Event Handlers from within JavaScript
`Event Emulation Methods
`Summary
`
`5 Objects in JavaScript
`What Are Objects?
`What Is Object-Oriented Programming?
`Object Types and Instances
`Creating Object Types
`JavaScript Object-Based Programming Features
`The JavaScript Object Model
`Using Properties
`Using Methods
`Creating Instances of Objects
`Navigator Objects
`The Navigator Object Hierarchy
`Hierarchical Object Identifiers
`Other Predefined Object Types
`The Date Object Type
`The string Object Type
`The Math Object
`Color Constants
`Defining Object Types
`Definition of table.js
`Using the table Object
`Adding Properties and Methods to an Object Type
`Arrays Are Objects
`Using Functions as Objects
`Summary
`
`1~11;Jlil Using Predefined Objects and Methods
`
`6 Windows and Frames
`The Window Object
`Opening and Closing Windows
`Communicating with the User
`Displaying Status Information
`Using the Window Synonyms
`Working with Timeouts
`
`Table of Contents
`
`150
`153
`155
`
`157
`158
`159
`160
`160
`164
`166
`166
`168
`168
`169
`171
`172
`178
`178
`182
`185
`188
`188
`190
`192
`194
`197
`198
`199
`
`200
`
`203
`204
`207
`212
`213
`213
`214
`
`xv
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Table of Contents
`
`The Frame Object
`Tic Tac Toe
`The Document Object
`Generating Document Contents
`Accessing Document Contents
`Working with Colors
`Summary
`
`7 Forms Processing
`The Form Object
`Accessing Forms within JavaScript
`Accessing Form Elements
`Using Form Event Handlers
`Responding to User Actions
`Performing Local Form Processing
`Working with CGI Scripts
`Sending Form Data to a CGI Program
`Performing Local Form Processing
`Summary
`
`8 Hidden Fields and Cookies
`Maintaining State Information
`Using Hidden Form Fields
`JavaScript and Hidden Form Fields
`Cookies
`How Is Information Stored in a Cookie?
`Using JavaScript with Cookies
`Example: A History Quiz
`Comparison: Cookies vs. Hidden Form Fields
`Summary
`
`9 Working with Links
`UR Ls
`The javascript: and about: Protocols
`The location Object
`Example Application Using location
`The link Object
`Example Application Using link: A Pair-Matching Game
`The link() Method
`The anchor Object
`
`xvi
`
`216
`217
`227
`229
`230
`232
`234
`
`237
`238
`240
`240
`248
`248
`257
`258
`258
`259
`263
`
`265
`266
`267
`268
`279
`280
`282
`286
`296
`297
`
`299
`300
`302
`305
`308
`311
`312
`325
`327
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`The history Object
`Standardized Navigation Scripts
`Summary
`
`10 Using Images
`The image Object
`Image Display Properties
`Other Image Properties
`Dynamic Image Display
`Images and Animation
`Image Maps and the area Object
`Working with Image Maps
`Summary
`
`11 Doing Math
`The Math Object
`Mathematical Constants
`Mathematical Functions
`Rounding Functions
`Comparison Functions
`Algebraic Functions
`Logarithmic and Exponential Functions
`Trigonometric Functions
`Random Number Generation
`Using Math Functions in Scripts
`Example Project: A JavaScript Calculator
`Summary
`
`1211;11111 Sample JavaScript Applications
`
`12 Web Page Widgets
`What's a Widget?
`Including Advertisements in Your Web Pages
`Fixed Ads
`Random Ads
`User-Selected Ads
`Usage Counters for Tabulating "Hits"
`Web Page Access Counters
`Web Site Access Counters
`
`Table of Contents
`
`328
`329
`333
`
`335
`336
`338
`338
`339
`344
`348
`349
`355
`
`357
`358
`358
`359
`360
`360
`360
`360
`361
`361
`361
`362
`372
`
`374
`
`377
`378
`378
`379
`381
`383
`389
`389
`392
`
`xvii
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Table of Contents
`
`Time Usage Counters
`Nag Counters
`Scrolling Messages
`Scrolling Text
`Scrolling Images
`Adding Simple Animation
`Page Format Preferences
`Summary
`
`13 Desktop Accessories
`Calendar
`Calculator
`To-Do List
`World Clock
`Assembling the Desktop
`Summary
`
`14 Online Catalogs
`Developing a Catalog without a CGI Program
`Tailoring a Catalog Based on User Preferences
`Adding Multimedia Features
`Summary
`
`15 Site Searching Tools
`Search Forms
`Search Engines
`Connecting Search Forms to Search Engines
`Local Search Engines
`Summary
`
`16 Game Programming
`Poker Machine
`A Board Game: "Web Walk"
`Summary
`
`lq!!:il''' Integrating Java and JavaScript
`17
`Introduction to Java
`What Is Java?
`
`xviii
`
`396
`399
`400
`401
`403
`405
`407
`412
`
`415
`416
`425
`430
`436
`438
`440
`
`443
`444
`457
`466
`476
`479
`480
`487
`489
`497
`509
`
`511
`512
`526
`544
`
`546
`
`549
`550
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Table of Contents
`
`Java Is Platform-Independent
`Java Is Object-Oriented
`Java Is Familiar
`Java Is Simpler and More Reliable
`The Java API Supports Window and Network Programming
`Java Supports Executable Web Content
`Java Is Secure
`Java Is Free
`Java vs. JavaScript
`Compiled vs. Interpreted
`Object~Oriented vs. Object-Based
`Strongly Typed vs. Loosely Typed
`Browser Window vs. Full Browser Interaction
`The Java Development Kit
`Learning Java
`The Java API
`Programs vs. Applets
`An Example Console Program .
`An Example Windows Program
`An Example Applet
`Summary
`
`18 Communicating with Applets
`Accessing Java Methods from within JavaScript
`Accessing Applets from within JavaScript
`Declaring Public Classes, Methods, and Variables
`Placing the Netscape java_version File in Your CLASSPATH
`Loading an Applet
`Using the applet Object
`My FancyText Example
`Using JavaScript in an Applet
`Using the MAYSCRIPT Attribute
`Importing netscape.javascript
`Creating a Handle to a JavaScript Window
`Using getMember()
`Using eval() .
`Reading Values Entered in a Form
`Other JSObject Methods
`Summary
`
`550
`551
`551
`552
`552
`552
`553
`553
`553
`554
`554
`555
`556
`557
`558
`558
`558
`559
`560
`563
`565
`
`567
`568
`570
`570
`571
`571
`572
`572
`574
`575
`575
`576
`577
`578
`578
`580
`581
`
`xix
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Table of Contents
`
`19 Developing Combined Applications with LiveConnect 583
`584
`A JavaScript Jukebox
`591
`Graphlt!
`Summary
`601
`
`l~1!UIM Working with Plug-Ins
`
`20 How Plug-Ins Work
`Popular Plug-Ins
`LiveAudio
`Live3D
`Media Player
`Quick Time
`Live Video
`Adobe Acrobat
`Pointcast
`Macromedia Shockwave
`NCompass ScriptActive
`Corel CMX Viewer
`Plug-In Resources
`Plug-Ins in Action
`Embedded Plug-In Documents
`How the SRC Attribute Is Processed
`Plug-In Documents Referenced as URLs
`Plug-Ins as Embedded Applications
`The Interface between Navigator and Plug-Ins
`Summary
`
`21 Accessing Plug-Ins with JavaScript
`Working with MIME Types
`Determining Installed Plug-Ins
`How Help > About Plug-ins Works
`Detecting Plug-Ins
`Accessing Plug-Ins from within JavaScript
`Summary
`
`22 Advanced Use of Plug-Ins
`Netscape's Plug-In Documentation
`Live Video
`LiveAudio
`
`xx
`
`602
`
`605
`606
`606
`608
`609
`610
`611
`612
`613
`614
`615
`616
`616
`617
`618
`619
`620
`620
`622
`625
`
`627
`628
`630
`633
`636
`638
`643
`
`645
`646
`646
`647
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`The netscape.plugin.Plugin class
`Listing Plug-In Methods
`Synchronizing Multiple Plug-Ins
`Assisting Users in Installing Plug-Ins
`Developing Your Own Plug-Ins
`Summary
`
`l~11Util Advanced Applications
`
`23 JavaScript Style Sheets
`What Are Style Sheets?
`JavaScript Style Sheets versus Cascading Style Sheets
`An Introductory Example
`Defining Style Sheets
`The <STYLE> Tag
`The <SPAN> Tag
`Using the <LINK> Tag to Include Styles
`Using Multiple Style Sheets
`Summary
`
`24 Layers and Multimedia Applications
`Using Layers
`The Layer Tags
`Windowed Elements
`The layers Array and layer Object
`A Slide Show Example
`Working with Audio
`Performing Animation
`Using Video
`Summary
`
`25 VRML and Live3D
`Introduction to VRML
`An Overview of the VRML Language
`A Simple VRML Example
`Using VRML Links
`Using JavaScript to Generate VRML
`Scripting and VRML 2.0
`Summary
`
`Table of Contents
`
`650
`650
`653
`656
`659
`660
`
`662
`
`665
`666
`667
`668
`670
`670
`684
`686
`688
`688
`
`691
`692
`692
`694
`694
`695
`701
`705
`708
`711
`
`713
`714
`716
`718
`723
`727
`731
`731
`
`xxi
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Table of Contents
`- -------- --- - - - - - - - - - - - - - - - - - - - - - - - - -
`
`I~,! ;j 1'1 li Server Programming
`26
`Interfacing JavaScript with CGI Programs
`When to Use CGI Programs
`How CGI Programs Work
`Getting Data from the Web Server
`Sending Data Back to the Web Server
`The General Design of a CGI Program
`A Shell Script Example
`Interfacing JavaScript Scripts with CGI Scripts
`Returning JavaScript from CGI Programs
`Summary
`
`27 Working with LiveWire
`The LiveWire Toolset
`A Simple Live Wire Example: "simple"
`Building the Example Application
`Running the Application
`How the Application Works
`The LiveWire Compiler
`Site Manager
`Application Manager
`Server-Side JavaScript Programming
`Server-Side Objects
`The request Object
`The client Object
`The project Object
`The server Object
`File Input and Output
`Opening Files
`Closing Files
`Accessing Files
`Locking File Access
`A Fuller Example: "diskette"
`The Files of the diskette Application
`Building and Running the diskette Application
`State Maintenance
`The Client-Cookie Approach
`The Client-URL Approach
`The Server-IP Approach
`
`xx ii
`
`732
`
`735
`736
`737
`738
`743
`745
`746
`750
`754
`757
`
`759
`760
`762
`763
`769
`770
`770
`772
`773
`775
`777
`778
`787
`787
`788
`789
`789
`790
`790
`792
`792
`793
`799
`802
`802
`803
`803
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Table of Contents
`
`The Server-Cookie Approach
`The Server-URL Approach
`Which Approach Should I Use?
`Server Functions
`Summary
`
`28 Accessing Databases with LiveWire Pro
`Databases vs. Files
`LiveWire Pro to the Rescue
`Setting Up the Informix Online Workgroup Server
`Using LiveWire Pro
`. The database Object
`Locks and Connections
`Executing SQL
`Using the Cursor
`Transaction Processing
`Error Handling
`Structured Query Language
`Adding, Deleting and Updating Rows
`Querying Tables
`Updating the diskette Application
`Creating a New Database
`Creating a New Database Table
`Adding Database Support to diskette
`Viewing the Database
`Providing SQL Access to orders
`Summary
`
`29 Creating Distributed Applications
`The Three-Tiered Architecture of Distributed Systems
`Characteristics of Distributed Systems
`Advantages of Distributed Applications
`Distributed Applications and the Web
`Implementing the User-Interface Layer on Web Browsers
`Implementing the Functional Layer Using Web Clients and
`Servers
`Implementing the Database Layer
`A Distributed Scheduling System
`How the Scheduling Application Works
`Overview of the Files Used to Implement the Scheduling
`Application
`
`804
`804
`805
`805
`806
`
`809
`810
`814
`815
`817
`818
`819
`820
`821
`823
`824
`825
`826
`828
`829
`829
`830
`831
`834
`837
`840
`
`843
`844
`845
`847
`849
`850
`
`851
`851
`852
`852
`
`863
`
`xx iii
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Table of Contents
`
`The schedule Database Structure
`Description of the Scheduling Application Code
`The admsched Application
`The schedule Application
`Building and Running the Scheduling Application
`Summary
`
`30
`
`Integrating Existing Application Components
`Netscape ONE
`Internet Foundation Classes
`Installing the IFC
`Using AppFoundry
`Sample AppFoundry Applications
`Downloading and Installing the TERP Application
`Running the TERP Application
`Tailoring the Application
`JavaBeans and Portable Applications
`A Word about Plug-Ins
`Summary
`
`31 Building an Intranet
`Intranet Sites vs. Internet Sites
`Intranet Websites
`Exploring the Airius Virtual Intranet
`The Internal Web vs. the External Web
`Focus
`Standardization
`Bandwidth
`Mission-Critical Nature
`Need for Security
`Summary
`
`32 Security Considerations
`Internet Security Threats
`Threats to the Website Manager
`Threats to the Web User
`Web Security Issues
`The Webmaster's Perspective
`The Web User's Perspective
`Summary
`
`867
`869
`870
`877
`895
`896
`
`899
`900
`901
`902
`903
`903
`908
`909
`911
`913
`914
`915
`
`917
`918
`920
`921
`932
`933
`933
`934
`935
`935
`936
`
`939
`940
`940
`941
`941
`942
`947
`951
`
`xx iv
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`i ~:! :j '''ii I Appendixes
`A HTML Reference
`Document Structure
`Document Head
`Document Body
`Frame Sets
`Comments
`Text Markup
`Anchors and Links
`Images and Image Maps
`Horizontal Rules
`Client-Side Image Maps
`Server-Side Image Maps
`Forms
`The <INPUT> Tag
`The <SELECT> Tag
`The <TEXTAREA> Tag
`The <KEYGEN> Tag
`Tables
`Embedded Objects
`Scripting
`Applets
`Style Sheets
`Layers
`Character Entities
`Colors
`
`B JavaScript Reference
`Objects
`Anchor
`Applet
`Area
`Array
`Boolean
`Button
`Checkbox
`Date
`document
`
`Table of Contents
`
`952
`
`955
`956
`956
`957
`957
`958
`958
`961
`961
`962
`962
`963
`963
`964
`965
`965
`965
`965
`967
`967
`968
`968
`969
`970
`970
`
`973
`974
`975
`975
`975
`976
`976
`977
`977
`978
`979
`
`xxv
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Table of Contents
`
`event
`File Upload
`Form
`Frame
`Function
`Hidden
`history
`Image
`layer
`Link
`location
`Math
`Mime Type
`navigator
`Number
`Option
`Password
`Plugin
`Radio
`Reset
`Select
`String
`Submit
`Text
`Textarea
`window
`Functions
`escape( string)
`isNaN(value)
`parseFloat(string)
`parselnt(string [,radix])
`taint( element)
`unescape(string)
`untaint(element)
`Color Constants
`c Java 1.1 Reference
`Program Structure and Terminology
`The package Statement
`The import Statement
`
`xx vi
`
`981
`981
`982
`982
`983
`984
`984
`985
`985
`987
`987
`988
`989
`990
`990
`991
`992
`992
`993
`994
`994
`995
`996
`997
`998
`999
`1001
`1001
`1001
`1001
`1001
`1002
`1002
`1002
`1003
`
`1007
`1008
`1008
`1008
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`The CLASSPATH
`The main() Method
`Program Elements
`Comments
`Identifiers
`Keywords
`Data Types
`Variables
`Declarations
`Statements and Local Variable Declarations
`Statement Block
`Local Variable Declarations
`Statement Labels
`Empty Statement
`Assignment- Statement
`Method Invocation
`If Statement
`Switch Statement
`For Statement
`While Statement
`Do Statement
`Break Statement
`Continue Statement
`Try Statement
`Return Statement
`Operators
`Java 1.1 API
`
`D ECMA Standardization of JavaScript
`The Development of JavaScript
`JavaScript Standardization and ECMA
`Netscape's Specification
`Microsoft's Specification
`Comparing the Two Specifications
`Limits of Standardization
`Online Updates
`
`Index
`
`Table of Contents
`
`1009
`1009
`1010
`1010
`1010
`1011
`1011
`1013
`1013
`1016
`1017
`1017
`1017
`1017
`1017
`1018
`1018
`1018
`1018
`1019
`1019
`1019
`1019
`1019 .
`1020
`1020
`1022
`
`1025
`1026
`1026
`1027
`1028
`1029
`1030
`1031
`
`1032
`
`xxvii
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Chapter 6 • Windows and Frames
`
`Working with Timeouts
`The setTimeout () and clearTimeotlt () methods provide a clever way to
`wait a specified amount of time for a user to perform a particular action and, if the
`action does not occur within the specified time, perform timeout processing. The
`setTimeout () method identifies an expression to be evaluated after a specified
`number of milliseconds; it is this expression that performs the timeout processing.
`
`The setTimeout () method returns a value that is used to identify the time(cid:173)
`out. It is usually assigned to a variable as shown in the following example:
`
`timVar = setTimeout ("timeoutProcessing() ", 10000)
`
`In the above statement, the set Timeout () method is invoked to perform
`the timeout processing specified by the timeoutProcessing () function after
`10,000 milliseconds (10 seconds) have elapsed. The setTimeout () method returns
`a value that identifies the timeout. This value is assigned to the timVar variable.
`
`The clearTimeout () method is used to cancel a timeout before it occurs and
`prevent the timeout processing from being performed. It takes the value of the
`timeout as an argument. For example, to clear the timeout created above, use the
`following statement:
`
`clearTimeout( t imVar)
`
`The above statement clears the timeout identified by timVar. This prevents the
`timeoutProcessing () from being invoked after the timeout period has occurred.
`
`The setinterval () and clearinterval () methods are similar to set (cid:173)
`Timeout () and clearTimeout ().The setinterval () method differs from
`setTimeout () in that it repeatedly executes a function or evaluates an expres(cid:173)
`sion after the timeout is expired.
`
`Listing 6.4 provides a more concrete example of performing timeout processing.
`It generates the Web page shown in Figure 6.6 and sets a ten-second timeout for
`the user to click on the provided button. If the user does not click on the button
`within ten seconds the alert dialog box shown in Figure 6.7 is displayed. If the user
`does click on the button within ten seconds the button's onClick event handler
`clears the timeout and congratulates the user.
`
`Listing 6.4. A timeout processing example <ch06-04.htm>
`<HTML)
`<HEAD>
`
`214
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`The Window Object
`
`<TITLE)Timeout Program</TITLE)
`<SCRIPT LANGUAGE="JavaScript">< 1-(cid:173)
`function setTimer() (
`timer=setTimeout("alert('Too slow! ')" ,10000 )
`
`function clearTimer() (
`clearTimeout(timer)
`alert("Congratulationsl")
`
`}
`II -->< /SCRI PT>
`<!HEAD>
`<BODY)
`<SCRIPT LANGUAGE="JavaScript"><l -(cid:173)
`setTimer()
`II -- ><!SCRIPT>
`<FORM>
`<INPUT TYPE="BUTTON" VALUE~ 11 Click here within ten seconds."
`ONCLICK="clearTimer()">
`</FORM)
`</BODY)
`<!HTML)
`
`-, 1, Netscape
`
`F I GURE 6.6
`Opening window for
`timeout processing
`example (Listing 6.4)
`
`[T 1meoul Progrdm)
`ll.ookn•ark• Qptions
`
`(lw
`
`~I ~.1 ! I R~d
`What's Cool? I Destinations I Net Sedrch I People
`
`C·\WINDOWS\Desktop\Ch06\ch06-04.htm
`
`m!IJil £1
`
`Software I
`
`Click here within ten seconds
`
`--
`
`215
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`The location Object
`
`r.• Netscape
`[lnfmmation about the Netscdpe disk cache)
`tdlt ~ICW yo !looKllldf~> .Qpt101»
`.QtreCIOI}' ~1ndow l:Jelp
`
`111~13
`
`FIGURE 9.4
`
`Loading about:cache dis(cid:173)
`plays information about
`the current state of the
`disk cache.
`
`Disk Cache statistics
`
`Ma:ximwn size: 5120000
`CWTent size: 1210178
`Nwnber of files in rache: 17
`Average cache file size: 71186
`
`URL: lli!J2jihome.netscaoe L''1UlllnAQeslnav home g>;
`Content. Length: 1664
`Content type: image/gtf
`Local filename: MOP7RE18.GIF
`Last Moctif1ed: Wed Sep 18 14:02:22 1996
`Expires: No expirati0n date sent
`
`URL: http/ihome.netscape.comlunageslhome igloo JPg
`Content Length: 14407
`Content type: image/jpeg
`Local filename: MOP7RE14JPG
`La!>t Modified: Wed J\Ul 05 18:22 27 1996
`Expires: No expu-ation date sent
`..LI~ i Document Done
`
`The location Object
`
`JavaScript uses the location object to access the URL of the current document
`that is loaded in a window. The location object contains properties that describe
`the various parts of the URL. These properties are summarized in Table 9.2.
`
`TABLE 9. 2
`
`Properties of the location object
`
`Property
`
`Description
`
`hash
`
`h os t
`
`The anchor part of the URL (if any).
`
`The hostname:port part of the URL.
`
`305
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Chapter 9 • Working with Links
`
`TAB LE 9 . 2
`
`Properties of the locat ion object (continued)
`
`Property
`
`Description
`
`ho stn ame
`
`The hostname part of the URL
`
`href
`
`The entire URL.
`
`pat hn ame
`
`The pathname part of the URL
`
`po rt
`
`The port part of the URL
`
`pr otocol
`
`The protocol part of the URL It includes the colon following the protocol name.
`
`sea r ch
`
`The query string pa rt of the URL
`
`.-'• Netscape - (About Plug-ms)
`
`~r-JEI
`
`FIGURE 9.5
`
`Loading about:plugins
`displays information
`about the plug-ins your
`browser has installed.
`
`Installed plug-ins
`
`For more mformabon on Netscape plug-ms, chck here
`
`Adobe Acrobat
`
`File name C:\PROGRAM
`FILES\NETSCAPE\NA VIGATOR\PROGRAM1plugins\nppdf32 dll
`
`Netscape Navigator Plug-m for Acrobat.
`
`Mime Type
`
`apphcattonfpdf
`
`Description
`
`Acrobat
`
`Live3D Plu&in DLL
`
`Ft!e name C \PF OGRAM
`::rl6!.ll DocumenL Done
`
`306
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`The location Object
`
`The location object is a property of the window object. If the location
`object of a window is modified, then the browser attempts to load the document
`specified by the modified URL into the window. For this reason, you should use
`the href property to modify the entire URL at a single time, rather than sequen(cid:173)
`tially modifying each of the parts of the URL.
`
`NOTE
`
`The document object also contains a location property. This property
`is read-only and cannot be modified to load a new document. you should
`not plan on using this property, because it will be deleted in future ver(cid:173)
`sions of JavaScript. Instead, use the href property of the location
`property of the window object.
`
`The location object has two methods- reload () and replace () . The
`reload () method causes the current document of a window to be reloaded
`according to the policy used by the browser's Reload button. This policy allows a
`document to be reloaded from the server in one of the following three ways:
`
`• Every time. The document is reloaded from the server every time.
`
`• Once per session. The document is reloaded from the server once per session
`if the document's date on the server indicates that it is newer than the docu(cid:173)
`ment stored in cache. If the document is not in the cache, it is loaded from
`the server.
`
`• Never. The document is reloaded from cache, if possible. Otherwise, it is
`loaded from the server.
`
`If true is passed as an argument to the reload () method, then the document
`is unconditionally loaded from the server.
`
`The replace () method takes a URL as a parameter, and loads the document
`at the specified URL over the current document in the current document history
`list. This prevents the user from returning to the previous document by clicking
`the browser's Back button.
`
`The location object does not have any events.
`
`307
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Chapter 9 •Working with Links
`
`Example Application Using location
`The location object is a simple object with which to work It is usually used to
`load a new document or to access individual parts of a document's URL. Listing 9.1
`provides an example of the location object's use.
`
`Open the file 1 o ad - ur 1 . h trn with your browser and it will display the form
`shown in Figure 9.6. This form lets you enter simple URLs that use the file:, http:,
`and ftp: protocols. You can enter a host name and path to further specify the
`URLs. When you click on the Load URL button, the document at the specified
`URL is displayed in the bottom frame of the window, as shown in Figure 9.7.
`
`The load - u r 1 . h trn file is shown in Listing 9 .1. It sets up a two-row frame set.
`The file u r 1 - form . h trn is loaded in the top row and b 1 ank . h trn is loaded in the
`bottom row. The url-fo r rn. htrn file is shown in Listing 9.2 and the blank. htrn
`file is shown in Listing 6.8 of Chapter 6.
`
`..+< Nehcape
`[Lood URL)
`t• Ed« y..,,
`'.Jc
`f!ool ,,,.,,
`
`!.!Pilon' Jl.vectoiy ~mow l:lelp
`
`111£!1 Ei
`
`I ~ I ~
`
`! I I
`
`_±UU_fj , .~,J
`
`~ Location: fi!e:///ClA~llNDOWS/D e>ktop/ch09/load-wl.htrn
`
`Select protocol:~
`
`Enter host name
`
`Enter patlr ~=-~=~-~=--~--"
`
`Loocl URL
`
`FIGURE 9.6
`
`The Load URL form lets
`you enter a URL part by
`part. <Listing 9.1 l
`
`308
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`The location Object
`
`- D x
`
`,ti~ I
`
`FIGURE 9.7
`
`The Load URL form lets
`you load Netscape's
`home page. (Listing 9.1)
`
`f.io .Edit
`
`l{iew
`
`~<r; 1 ,0~-,1 a I~ .~ 1
`
`Select protocol- p;;tp"3
`
`Enter host name: Jhome.nelsCBpe.com ___ ~-----..dl
`
`Enter path:
`
`) I J
`,ilJ_ W l l C 0 M l I 0
`f •
`l ~);-'
`NETSCAPE
`~~~ ~:~
`I ONl StOI'
`C.lH:Ml\l I
`Nl:ISCAl'l I COMl'ANY t!I I INlHANtl
`
`UC>Nt
`
`MSIH/\NU SOflWAHt
`
`UUIJNAll~ l'IWUUCU
`
`1UlU110NS
`
`UtVtUC.l
`ONUNl
`
`NETSCAPE DIRECTORY SERVER MANAGES INFORMATION
`
`NOVEMBER 2-4: Netscape announces the availability of
`Netscape Directory Setvei: I . 0 for Unix. Get the
`
`DOWNLOAD OR PIJRCHASE TIIE L ATEST
`NETSCAPE SOFIWARE
`
`I Select here and click below
`
`EJ
`
`Listing 9. 1. Using the location object Uoad-url.htm)
`<HTML>
`<HEAD)
`<TITLE)Load URL</TITLE)
`<!HEAD>
`<FRAMESET ROWS= "200,*" BORDER= l O>
`<FRAME SRC- 11 url-form.htm 11 >
`<FRAME SRC= 11 blank.htm 11 >
`</FRAMESET>
`</HTML>
`
`Listing 9.2. A form for entering a URL <url-form.htm)
`<HTML>
`<HEAD)
`
`309
`
`Starbucks, Ex. 1075
`Starbucks v. Ameranth, CBM2015-00099
`
`
`
`Chapter 9 • Working with Links
`
`/
`
`<TITLE)Load URL</TITLE)
`<SCRIPT LANGUAGE- 11 JavaScript 11 ><1 -(cid:173)
`function loadFrames() {
`ix = document.URLform.protocol.options.selectedindex
`urlString = d