`
`,,, ~
`
`j~ ,
`
`1
`
`R'.
`
`~, _
`
`.-,
`
`.~
`
`a
`
`TM ~:,,
`
`i
`
`P AUL I~00 ROS
`M ICHELE DEWOLFE
`
`;~H
`
`LUEPRINTS TO A WORLD BEYOND HTML!
`
`y s'
`
`.. —~ `
`
`g':
`
`~.
`
`F.
`
`i
`
`-~r~
`
`,3
`
`b
`
`J
`
`S
`
`I~ ,,:~
`
`e~~
`
`~' r
`~, i ~'
`
`~;.
`
`g3
`r '
`
``: _~-
`
`:t ~
`
`,~
`
`,'~
`
`Facebook's Exhibit No. 1014
`Page 1
`
`
`
`-u
`
`~_~
`
`~ . ~
`
``~~~y~ F
`pY'j r~
`
`'
`
`a
`
`+~
`
`Y.
`.~
`
`4~9, C W f
`
`O
`
`
`
`y ,~
`a ~ ,
`
`~~
`
`UNWEfiSEW Q? Pi‘Tffiifllfii‘iH
`~~ ~~~~~~~~f~
`Lo~~~.~Y
`
`A? GfiEEfiSEfiRG
`
`~;~;
`
`~1
`
`HERMY
`
`
`
`Facebook's Exhibit No. 1014
`
`Page 2
`
`Facebook's Exhibit No. 1014
`Page 2
`
`
`
`How to Order:
`
`For information on quantity discounts contact the publisher:
`Prima Publishing, P.O. Box 1260BK, Rocklin, CA 95677-1260;
`(916) 632-4400. On your letterhead include information con-
`cerning the intended use of the books and the number of books
`you wish to purchase. For individual orders, turn to the back of
`this book for more information.
`
`Facebook's Exhibit No. 1014
`Page 3
`
`
`
`~
`
`o
`
`Paul Kooros
`Michele DeWolfe
`
`~ ~
`
`~s✓
`
`SY
`
`e
`
`fIL ~i :'
`
`~sl
`
`r
`
`P RIMA PUBLISHING
`
`Facebook's Exhibit No. 1014
`Page 4
`
`
`
`JavaScript
`
`Publisher:
`Don Roche, Jr.
`Associate Publisher:
`Ray Robinson
`Managing Editor:
`Heather Kaufman Urschel
`Senior Acquisitions Editor:
`Alan Harris
`Pro~eCt Editor:
`Anne Owen
`Technical Reviewer:
`Jim O'Donnell
`Indexer:
`Sherry Massey
`
`I~ TM
`
`is a trademark of Prima Publishing, a division
`of Prima Communications, Inc.
`
`Prima PublishingTM is a trademark of Prima
`Communications, Inc.
`
`Prima Publishing, Rocklin, California 95677.
`
`c0 1996 by Paul Kooros aand Michele DeWolfe.
`All rights reserved. No part of this book may be
`reproduced or transmitted in any form or by any
`means, electronic or mechanical, including photo-
`copying, recording, or by any information storage
`or retrieval system without written permission from
`Prima Publishing, except for the inclusion of brief
`quotations in a review.
`Prima Publishing and the authors) have attempted
`throughout this book to distinguish proprietary
`trademarks from descriptive terms by following the
`capitalization style used by the manufacturer.
`Information contained in this book has been
`obtained by Prima Publishing from sources
`believed to be reliable. However, because of the
`possibility of human or mechanical error by our
`sources, Prima Publishing, or others, the Publisher
`does not guarantee the accuracy, adequacy, or com-
`pleteness of any information and is not responsible
`for any errors or omissions or the results obtained
`from use of such information.
`
`ISBN: 0-7615-0685-3
`Library of Congress Catalog Card Number: 96-68062
`Printed in the United States of America
`
`9 6 97 98 99
`
`DD
`
`10 9 8 7 6 5 4 3 2 1
`
`Facebook's Exhibit No. 1014
`Page 5
`
`
`
`JavaScript
`
`~~t~
`
`.~ ~~ Contents at a Glance
`
`Introduction, 1
`1 Introducing JavaScript, 5
`2 Getting Started: JavaScript Basics, 11
`3 HTML Overview and Primer, 63
`4 The JavaScript Object Model, 87
`5 Creating and Using JavaScript Objects, 97
`6 JavaScript Events, 109
`7 JavaScript Objects, 127
`8 JavaScript Methods, 201
`9 JavaScript Properties, 277
`A Colors, 311
`Glossary, 323
`Index, 327
`
`Facebook's Exhibit No. 1014
`Page 6
`
`
`
`JavaScript
`
`f~
`
`fi?
`
`t~.~~
`
`!~
`
`Table of Contents
`
`1 5
`
`=`s~~`
`
`lntroc~uction
`
`Chapter 7
`Introducing JavaScrint
`
`Past and Future of JavaScript ................................................................................7
`What's Missing in JavaScript ...........:....................................................................8
`The Nuts and Bolts of Creating JavaScript ............................................................8
`Creating a JavaScript Program ............................................................................................9
`Chapter 2
`Getting Started: java5cri~t Basics
`
`11
`
`JavaScript and HTML ..........................................................................:...............12
`Generating Output .............................................................................................................12
`JavaScript's Context within HTML ..................................................................................13
`A Little about the JavaScript Object Mode1 .....................................................................14
`The Building Blocks ofJavaScript ........................................................................15
`Comments and Prograuiiuing Style .................................................................................16
`Variable Names ...................................................................:...............................................19
`Variables ..............................................................................................................................20
`JavaScript Keywords ...........................................................................................................22
`Data Types and Values ..............................................................................:........................23
`Literals .................................................................................................................................26
`Expressions ..........................................................................................................................30
`Statements and Blocks .......................................................................................................31
`Operators.............................................................................................................................33
`Operator Precedence ..........................................................................................................43
`ControlFlow Structures ....................................................................................................44
`Arrays...................................................................................................................................5 6
`Summary ............................................................................................................60
`Chapter 3
`An HTML Overview and Primer
`
`G3
`
`A Little about HTML ..........................................................................................64
`
`Creating HTML Tags ..........................................................................................65
`
`HTML Attributes ................................................................................................66
`
`Facebook's Exhibit No. 1014
`Page 7
`
`
`
`JavaScript
`
`HTML Document Structure ................................................................................67
`HTML <HEAD> Section .....................................................................................................68
`HTML <BODY> Section .....................................................................................................68
`HTML Tags and JavaScript Properties ................................................................70
`<A>—Anchor Tag ................................................................................................................71
`<FORM>—Form Tag ...........................................................................................................73
`<INPUT~—Input Tag ..........................................................................................................74
`~TEXTAREA~—Textarea Tag .............................................................................................80
`<SELECT>—Select Tag ........................................................................................................81
`<FDRM> 'Z'ags ......................................................................................................................82
`Frames and Framesets ........................................................................................82
`<FRAMESET>—Frameset Tag ............................................................................................83
`<FRAME>—Frame Tag ........................................................................................................84
`Summary ............................................................................................................85
`Chapter 4
`The JavaScri~t Object Mociel
`
`87
`Quick Review of Object-Oriented Concepts ........................................................88
`OUjects, Properties, Methods, and Events .......................................................................88
`Advantages of Object-Oriented Programming ...............................................................89
`Abstraction, Encapsulation, Hierarchy, and Polymorphism ........................................89
`JavaScript Is Object Oriented, After All ...........................................................................91
`JavaScript Is Object-Based ..................................................................................92
`TheJavaScript Object Hierarchy ..........................................................................93
`AnExample of the JavaScript Object Hierarchy .............................................................93
`Summary ............................................................................................................95
`Chapter 5
`Creating and Using JavaScri~t Objects
`
`97
`Creating JavaScript Objects ................................................................................98
`Creating JavaScript Objects from HTML Objects ............................................
`.......99
`Arrays and JavaScript ........................................................................................103
`Arrays as JavaScript Objects ............................................................................................104
`Using the for..in Statement in JavaScript ........................................................................105
`Using the with Statement in JavaScript ..........................................................................106
`Summary ..........................................................................................................107
`Chapter 6
`JavaScrint Events
`
`109
`Definition ofJavaScript Events ..........................................................................110
`
`Facebook's Exhibit No. 1014
`Page 8
`
`
`
`JavaScript
`
`JavaScript Events ..............................................................................................111
`Focus and Blur Events .......................................................................................................112
`Change Event ......................................................................................................................113
`Select Event .........................................................................................................................113
`Click Event ..........................................................................................................................113
`MouseOver Event ...............................................................................................................114
`Submit Event ......................................................................................................................114
`Load Event ..........................................................................................................................114
`UnloadEvent ......................................................................................................................115
`Timer Events ......................................................................................................................115
`UsingJavaScript Events ....................................................................................116
`Summary ..........................................................................................................126
`Chapter 7
`JavaScript Objects
`
`~Z7
`
`Anchor Object ..................................................................................................128
`Button Object ....................................................................................................130
`Checkbox Object ................................................................................................132
`Date Object ......................................................................................................134
`
`Document Object ..............................................................................................138
`
`Elements Array ..................................................................................................142
`Form and Forms Array Object ............................................................................144
`
`Frames Object ..................................................................................................148
`Hidden Object ..................................................................................................152
`History Object ..................................................................................................154
`Links Object ......................................................................................................156
`
`Location Object ................................................................................................160
`
`Math Object ......................................................................................................163
`Navigator Object ..............................................................................................165
`Options Object ..................................................................................................166
`Password Object ................................................................................................167
`
`Radio Object ....................................................................................................169
`
`Reset Object ......................................................................................................175
`
`Select and Options Objects ................................................................................177
`String Object .............................................................................................
`
`..182
`
`Facebook's Exhibit No. 1014
`Page 9
`
`
`
`JavaScript
`
`Submit Object ....................................................................................................186
`Text Object ......................................................................................................189
`Textarea Object ................................................................................................192
`Window Object ..................................................................................................195
`Chapter 8
`JavaScript Methods
`
`Zoi
`Math Methods ..................................................................................................204
`Method abs .........................................................................................................................204
`Methodacos .......................................................................................................................205
`Methodasin .......................................................................................................................206
`Methodatan ......................................................................................................................206
`Methhod celZ ......................................................................................................................206
`Method cos .........................................................................................................................207
`Method exp ........................................................................................................................207
`Methodfloor .......................:..............................................................................................208
`Methodlog .........................................................................................................................208
`Methodmaac .......................................................................................................................209
`Method min ..............................:........................................................................................209
`Methodpow .......................................................................................................................210
`Methodrandom .................................................................................................................211
`Methodround .........:..........................................................................................................211
`Methodsin .........................................................................................................................212
`Methodsgrt ........................:...............................................................................................212
`Method tan ........................................................................................................................213
`Window Methods ............................................................................................213
`Method alert ......................................................................................................................213
`Method close (Window Object) ......................................................................................215
`Method confirm .................................................................................................................216
`Method open (Window Object) .......................................................................................217
`Methodprompt ..................................................................................................................219
`String Methods ................................................................................................220
`Method anchor ...................................................................................................................220
`Method big .........................................................................................................................221
`Method blink .....................................................................................................................222
`Method bold .......................................................................................................................222
`Method charAt ...........................................................................................................:.......223
`Methodfrxed ......................................................................................................................224
`Methodfontcolor ...............................................................................................................225
`Methodfontsize ..................................................................................................................226
`MethodindexOf .................................................................................................................227
`Methoditalics ....................................................................................................................229
`Method lastlndexOf ...........................................................................................................230
`
`Facebook's Exhibit No. 1014
`Page 10
`
`
`
`JavaScript
`
`Method link .......................................................................................................................231
`Method small .....................................................................................................................233
`Methodstrike .....................................................................................................................234
`Method sub ........................................................................................................................234
`Methodsubstring ...............................................................................................................235
`Methodsup ........................................................................................................................236
`Method toLowerCase ..........................................................................................................237
`Method toUpperCase ..........................................................................................................238
`History Methods ..............................................................................................240
`Method back ......................................................................................................................240
`Methodforward .................................................................................................................242
`Methodgo ..........................................................................................................................242
`Document Methods ..........................................................................................244
`Method clear ......................................................................................................................244
`Method close (Document Object) ....................................................................................245
`Method open (Document Object) ....................................................................................245
`Method write .....................................................................................................................246
`Method writeln ..................................................................................................................247
`Date Methods ..................................................................................................247
`MethodgetDate .................................................................................................................247
`MethodgetDay ...................................................................................................................248
`MethodgetHours ...............................................................................................................250
`MethodgetMinutes ............................................................................................................251
`MethodgetMonth ..............................................................................................................252
`MethodgetSeconds .............................................................................................................253
`MethodgetTime .................................................................................................................254
`MethodgetTimexoneOffset ................................................................................................256
`MethodgetYear .................................................................................................................:258
`Methodjiarse .....................................................................................................................259
`MethodsetDate ..................................................................................................................261
`MethodsetHours ................................................................................................................262
`MethodsetMinutes .............................................................................................................263
`MethodsetMonth ...............................................................................................................264
`MethodsetSeconds .............................................................................................................265
`MethodsetTime .................................................................................................................266
`MethodsetYear ..................................................................................................................267
`Method toGMTString ........................................................................................................268
`Method toLocaleString .......................................................................................................269
`Method UTC ......................................................................................................................270
`Form Methods ..................................................................................................271
`Method submit ...................................................................................................................271
`Methods Used by Multiple Objects ..................................................................271
`Method blur .......................................................................................................................271
`Method clearTimeout .........................................................................................................272
`
`Facebook's Exhibit No. 1014
`Page 11
`
`
`
`JavaScript
`
`Method click ......................................................................................................................273
`Methodfocus ......................................................................................................................274
`Methodselect ....................................:...................................................................:............274
`MethodsetTimeout ............................................................................................................275
`Chapter 9
`JavaScript Properties
`
`277
`
`Property action ..................................................................................................279
`Property alinkColor ............................................................................................280
`Property anchors ................................................................................................281
`Property appCodeName ......................................................................................281
`Property uppName ............................................................................................282
`Property appVersion ..........................................................................................282
`Property bgColor ..............................................................................................283
`Property checked ................................................................................................283
`Property cookie ..................................................................................................284
`Property defqultChecked ....................................................................................285
`Property defaultSe%cted ....................................................................................285
`Property defuultStatus ........................................................................................286
`Property defaultValue ........................................................................................287
`Property E ........................................................................................................288
`Property encoding ........................................................................................:.....288
`Property fSColor ................................................................................................289
`Property hash ....................................................................................................289
`Property host ....................................................................................................290
`Property hostname ............................................................................................291
`Property href ....................................................................................................291
`Property index ..................................................................................................292
`Property lastModi~ed ..........................................................................:.............292
`Property length ..................................................................................................293
`Property linkColor ............................................................................................294
`Property LN2 ....................................................................................................295
`Property LN90 ..................................................................................................295
`
`Facebook's Exhibit No. 1014
`Page 12
`
`
`
`JavaScript
`
`Property location ..............................................................................................296
`Property LOG2E ..............................................................................................296
`Property LOG70E ............................................................................................297
`Property method ................................................................................................297
`Property name ..................................................................................................298
`Property parent ................................................................................................299
`Property pathngme ............................................................................................300
`Property P/ ......................................................................................................301
`Property port ....................................................................................................301
`Property prototol ..............................................................................................302
`Property referrer ..............................................................................................302
`Property search ................................................................................................303
`Property selected ..............................................................................................303
`Property selected/ndex ........................................................................................304
`Property self ......................................................................................................305
`Property SQRT1_2 ............................................................................................306
`Property SQRT2 ................................................................................................306
`Property SQRT1_2 ............................................................................................306
`Property status ..................................................................................................307
`Property target ..............................................................................................:...307
`Property text ....................................................................................................308
`Property title ....................................................................................................309
`Property top ......................................................................................................309
`Property userAgent ............................................................................................310
`Appendix A
`Colors
`Glossary
`Index
`
`311
`323
`327
`
`Facebook's Exhibit No. 1014
`Page 13
`
`
`
`. JavaScript
`
`Functions can also call themselves recursively, meaning that a fiinc-
`tion may call itself. For example, you can implement the factorial
`program using a recursive function:
`
`{
`
`function factorial( n )
`if ( n = 0 )
`return 1;
`} else {
`return(n * factorial(n - 1));
`
`document.writeln("10 Factorial is
`
`+ factorial(10));
`
`An important characteristic of recursive functions is that every time
`it calls itself, it reduces the size of its task. The first time it is called, it
`reduces its problem to computing f a c t o r i a 1 (9 ), which it can multi-
`ply by 10 to obtain f a c t o r i a 1 (10) . As long as the problem it repeat-
`edly hands itself becomes increasingly smaller, it eventually is able to
`solve the problem directly. In this case, it knows directly that f a c to r -
`i a 1 (0) is 1. Many types of programming problems are handily solved
`with recursive functions. The capaUility to write recursive functions
`adds yet another tool to the programmer's tool belt.
`A~~ys
`The array is a data structure common to many pro