0% found this document useful (0 votes)
4 views

Professional JavaScript for Web Developers 1st Edition Nicholas C. Zakas pdf download

The document provides information about various eBooks available for download, including 'Professional JavaScript for Web Developers' by Nicholas C. Zakas. It outlines the contents of the book, including chapters on JavaScript basics, object-oriented programming, and browser interactions. Additionally, it includes author details and publication information.

Uploaded by

cabriogasca
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Professional JavaScript for Web Developers 1st Edition Nicholas C. Zakas pdf download

The document provides information about various eBooks available for download, including 'Professional JavaScript for Web Developers' by Nicholas C. Zakas. It outlines the contents of the book, including chapters on JavaScript basics, object-oriented programming, and browser interactions. Additionally, it includes author details and publication information.

Uploaded by

cabriogasca
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

Professional JavaScript for Web Developers 1st

Edition Nicholas C. Zakas pdf download

https://ebookname.com/product/professional-javascript-for-web-
developers-1st-edition-nicholas-c-zakas/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Professional Ajax 2nd Edition Programmer to Programmer


Nicholas C. Zakas

https://ebookname.com/product/professional-ajax-2nd-edition-
programmer-to-programmer-nicholas-c-zakas/

Security for Web Developers Using JavaScript HTML and


CSS Early Release Raw Unedited John Paul Mueller

https://ebookname.com/product/security-for-web-developers-using-
javascript-html-and-css-early-release-raw-unedited-john-paul-
mueller/

Pro JavaScript for Web Apps 1st Edition Adam Freeman

https://ebookname.com/product/pro-javascript-for-web-apps-1st-
edition-adam-freeman/

Perception of Faces Objects and Scenes Analytic and


Holistic Processes Advances in Visual Cognition 1st
Edition Mary A. Peterson

https://ebookname.com/product/perception-of-faces-objects-and-
scenes-analytic-and-holistic-processes-advances-in-visual-
cognition-1st-edition-mary-a-peterson/
The Complete Guide to Fasting Heal Your Body Through
Intermittent Alternate Day and Extended 1st Edition
Jason Fung

https://ebookname.com/product/the-complete-guide-to-fasting-heal-
your-body-through-intermittent-alternate-day-and-extended-1st-
edition-jason-fung/

Industrial Commodity Statistics Yearbook 2005


Production Statistics 1996 2005 United Nations

https://ebookname.com/product/industrial-commodity-statistics-
yearbook-2005-production-statistics-1996-2005-united-nations/

Electrocorrosion and Protection of Metals General


approach with particular consideration to
electrochemical plants 1st Edition Joseph Riskin

https://ebookname.com/product/electrocorrosion-and-protection-of-
metals-general-approach-with-particular-consideration-to-
electrochemical-plants-1st-edition-joseph-riskin/

LJMU Law Year One Optimize English Legal System 1st


Edition Angela Stanhope

https://ebookname.com/product/ljmu-law-year-one-optimize-english-
legal-system-1st-edition-angela-stanhope/

Microelectronics Failure Analysis Desk Reference 6th


edition Edition Edfas Desk Reference Committee

https://ebookname.com/product/microelectronics-failure-analysis-
desk-reference-6th-edition-edition-edfas-desk-reference-
committee/
Bangladesh s Quest for Inclusive Development Challenges
and Pathways 1st Edition Mustafa K. Mujeri

https://ebookname.com/product/bangladesh-s-quest-for-inclusive-
development-challenges-and-pathways-1st-edition-mustafa-k-mujeri/
Professional JavaScript™ for Web Developers
Professional JavaScript™ for Web Developers

Nicholas C. Zakas
Professional JavaScript™ for Web Developers
Copyright © 2005 by Wiley Publishing Inc. All rights reserved.
Published by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form
or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as
permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior
written permission of the Publisher, or authorization through payment of the appropriate per-copy fee
to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax
(978) 646-8700. Requests to the Publisher for permission should be addressed to the Legal Department,
Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317)
572-4355, or online at www.wiley.com/go/permissions.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR


MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR
COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL
WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTIC-
ULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMO-
TIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE
SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT
THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PRO-
FESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A
COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOT
THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN
ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A
POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR
THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY
PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE
THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED
BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.

For general information on our other products and services please contact our Customer Care Depart-
ment within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317)
572-4002.
Trademarks: Wiley, the Wiley Publishing logo, Wrox, the Wrox logo, and Programmer to Programmer
are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates. JavaScript is a
trademark of Sun Microsystems, Inc. in the United States and other countries. All other trademarks are
the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or
vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print
may not be available in electronic books.
Library of Congress Cataloging-in-Publication Data is available from the publisher.
ISBN-13: 978-0-7645-7908-0
ISBN-10: 0-7645-7908-8
Printed in the United States of America
10 9 8 7 6 5 4 3 2 1
About the Author
Nicholas C. Zakas is a user interface designer for Web applications, specializing in client-side technolo-
gies such as JavaScript, HTML, and CSS. Nicholas currently works as Senior Software Engineer, Design
Engineering, at MatrixOne, Inc. located in Westford, Massachusetts, USA.

Nicholas has a B.S. in Computer Science from Merrimack College, where he learned traditional pro-
gramming in C and C++. During college, he began investigating the World Wide Web and HTML in his
spare time, eventually teaching himself enough to be hired as Webmaster of a small software company
named Radnet, Inc. in Wakefield, Massachusetts, USA. It was there that Nicholas began learning
JavaScript and working on Web applications.

Nicholas can be reached through his Web site, http://www.nczonline.net/.


Credits
Vice President and Executive Group Publisher: Development Editor:
Richard Swadley Sharon Nash

Vice President and Publisher: Senior Production Editor:


Joseph B. Wikert Angela Smith

Acquisitions Editor: Technical Editor:


Jim Minatel Jean-Luc David, Wiley-Dreamtech India Pvt Ltd

Editorial Manager: Text Design & Composition:


Mary Beth Wakefield Wiley Composition Services
Acknowledgments

It takes more than just one person to write a book of this nature, despite the single name on the front
cover. Without the help of numerous individuals, this book would not have been possible.

First are foremost, thanks to everyone at Wiley Publishing, especially Jim Minatel and Sharon Nash, for
providing all the guidance and support that a new author needs.

Thanks to all those who offered their ideas on what a good JavaScript book should include: Keith
Ciociola, Ken Fearnley, John Rajan, and Douglas Swatski.

A special thanks to everyone who reviewed the subject matter ahead of time: Erik Arvidsson, Bradley
Baumann, Guilherme Blanco, Douglas Crockford, Jean-Luc David, Emil A. Eklund, Brett Fielder, Jeremy
McPeak, and Micha Schopman. All your input was excellent and made for a much better book.

Thanks to Drs. Ed and Frances Bernard for keeping me in tip-top health during the writing of this book
and the past few years.

Last, but certainly not least, thanks to my family, mom, dad, and Greg, and my extremely understanding
girlfriend, Emily. Your love and support helped take me from the proposal to the final published copy.

vii
Contents

Acknowledgments vii
Introduction xxi

Chapter 1: What Is JavaScript? 1


A Short History 1
JavaScript Implementations 3
ECMAScript 3
The Document Object Model (DOM) 6
The Browser Object Model (BOM) 9
Summary 9

Chapter 2: ECMAScript Basics 11


Syntax 11
Variables 12
Keywords 15
Reserved Words 15
Primitive and Reference Values 15
Primitive Types 16
The typeof operator 16
The Undefined type 17
The Null type 18
The Boolean type 18
The Number type 18
The String type 20
Conversions 21
Converting to a string 22
Converting to a number 23
Type Casting 24
Reference Types 25
The Object class 26
The Boolean class 27
The Number class 27

ix
Contents
The String class 29
The instanceof operator 32
Operators 33
Unary operators 33
Bitwise operators 37
Boolean operators 43
Multiplicative operators 46
Additive operators 47
Relational operators 49
Equality operators 50
Conditional operator 52
Assignment operators 52
Comma operator 53
Statements 53
The if statement 53
Iterative statements 54
Labeled statements 56
The break and continue statements 56
The with statement 58
The switch statement 58
Functions 59
No overloading 61
The arguments object 62
The Function class 63
Closures 65
Summary 66

Chapter 3: Object Basics 67


Object-Oriented Terminology 67
Requirements of object-oriented languages 68
Composition of an object 68
Working with Objects 68
Declaration and instantiation 68
Object references 69
Dereferencing objects 69
Early versus late binding 69
Types of Objects 70
Native objects 70
Built-in objects 81
Host objects 87

x
Contents
Scope 88
Public, protected, and private 88
Static is not static 88
The this keyword 89
Defining Classes and Objects 90
Factory paradigm 90
Constructor paradigm 92
Prototype paradigm 93
Hybrid constructor/prototype paradigm 94
Dynamic prototype method 95
Hybrid factory paradigm 96
Which one to use? 97
A practical example 97
Modifying Objects 99
Creating a new method 99
Redefining an existing method 100
Very late binding 101
Summary 102

Chapter 4: Inheritance 103


Inheritance in Action 103
Implementing Inheritance 104
Methods of inheritance 105
A more practical example 111
Alternative Inheritance Paradigms 115
zInherit 116
xbObjects 120
Summary 124

Chapter 5: JavaScript in the Browser 125


JavaScript in HTML 125
The <script/> tag 125
External file format 126
Inline code versus external files 127
Tag placement 128
To hide or not to hide 129
The <noscript/> tag 130
Changes in XHTML 131

xi
Contents
JavaScript in SVG 133
Basic SVG 133
The <script/> tag in SVG 134
Tag placement in SVG 135
The Browser Object Model 136
The window object 136
The document object 149
The location object 153
The navigator object 155
The screen object 156
Summary 157

Chapter 6: DOM Basics 159


What Is the DOM? 159
Introduction to XML 159
An API for XML 162
Hierarchy of nodes 163
Language-Specific DOMs 166
DOM Support 167
Using the DOM 167
Accessing relative nodes 167
Checking the node type 169
Dealing with attributes 169
Accessing specific nodes 171
Creating and manipulating nodes 173
DOM HTML Features 178
Attributes as properties 178
Table methods 179
DOM Traversal 182
NodeIterator 182
TreeWalker 187
Detecting DOM Conformance 189
DOM Level 3 191
Summary 191

Chapter 7: Regular Expressions 193


Regular Expression Support 193
Using a RegExp object 194
Extended string methods 195

xii
Contents
Simple Patterns 197
Metacharacters 197
Using special characters 197
Character classes 199
Quantifiers 201
Complex Patterns 205
Grouping 205
Backreferences 206
Alternation 207
Non-capturing groups 209
Lookaheads 210
Boundaries 210
Multiline mode 212
Understanding the RegExp Object 212
Instance properties 213
Static properties 214
Common Patterns 216
Validating dates 216
Validating credit cards 218
Validating e-mail addresses 222
Summary 223

Chapter 8: Browser and Operating System Detection 225


The Navigator Object 225
Methods of Browser Detection 226
Object/feature detection 226
User-agent string detection 226
A (Not So) Brief History of the User-Agent String 227
Netscape Navigator 3.0 and Internet Explorer 3.0 227
Netscape Communicator 4.0 and Internet Explorer 4.0 229
Internet Explorer 5.0 and higher 230
Mozilla 230
Opera 232
Safari 233
Epilogue 233
The Browser Detection Script 234
Methodology 234
First Steps 234
Detecting Opera 237

xiii
Contents
Detecting Konqueror/Safari 239
Detecting Internet Explorer 241
Detecting Mozilla 242
Detecting Netscape Communicator 4.x 243
The Platform/Operating System Detection Script 244
Methodology 244
First steps 245
Detecting Windows operating systems 245
Detecting Macintosh operating systems 247
Detecting Unix operating systems 248
The Full Script 249
Example: A Login Page 252
Summary 259

Chapter 9: All about Events 261


Events Today 261
Event Flow 262
Event bubbling 262
Event capturing 264
DOM event flow 265
Event Handlers/Listeners 266
Internet Explorer 267
DOM 268
The Event Object 270
Locating 270
Properties/methods 271
Similarities 274
Differences 276
Types of Events 279
Mouse events 280
Keyboard events 284
HTML events 286
Mutation events 291
Cross-Browser Events 292
The EventUtil object 292
Adding/removing event handlers 292
Formatting the event object 294
Getting the event object 299
Example 300
Summary 301

xiv
Contents

Chapter 10: Advanced DOM Techniques 303


Scripting Styles 303
DOM style methods 305
Custom tooltips 307
Collapsible sections 308
Accessing style sheets 309
Computed styles 312
innerText and innerHTML 314
outerText and outerHTML 315
Ranges 317
Ranges in the DOM 317
Ranges in Internet Explorer 329
How practical are ranges? 333
Summary 333

Chapter 11: Forms and Data Integrity 335


Form Basics 335
Scripting the <form/> Element 337
Getting form references 337
Accessing form fields 338
Form field commonalities 338
Focus on the first field 339
Submitting forms 340
Submit only once 341
Resetting forms 342
Text boxes 342
Retrieving/changing a text box value 343
Selecting text 344
Text box events 345
Select text automatically 345
Tab forward automatically 346
Limit textarea characters 347
Allowing/blocking characters in text boxes 349
Numeric text boxes with the up/down arrow keys 354
List Boxes and Combo Boxes 356
Accessing options 357
Retrieving/changing the selected option(s) 357
Adding options 359
Removing options 360

xv
Contents
Moving Options 361
Reordering options 361
Creating an Autosuggest Text Box 362
Matching 362
The guts 363
Summary 365

Chapter 12: Sorting Tables 367


The Starting Point — Arrays 367
The reverse() method 369
Sorting a One-Column Table 369
The comparison function 371
The sortTable() function 371
Sorting a Multicolumn Table 373
The comparison function generator 374
Modifying the sortTable() function 375
Sorting in descending order 376
Sorting with different data types 377
Advanced sorting 381
Summary 385

Chapter 13: Drag and Drop 387


System Drag and Drop 387
Drag-and-drop events 388
The dataTransfer object 393
The dragDrop() method 397
Advantages and disadvantages 399
Simulated Drag and Drop 399
The code 400
Creating drop targets 403
Advantages and disadvantages 405
zDragDrop 405
Creating a draggable element 406
Creating a drop target 406
Events 406
Example 408
Summary 409

xvi
Contents

Chapter 14: Error Handling 411


The Importance of Error Handling 411
Errors versus Exceptions 412
Error Reporting 413
Internet Explorer (Windows) 413
Internet Explorer (MacOS) 415
Mozilla (all platforms) 416
Safari (MacOS X) 417
Opera 7 (all platforms) 418
Handling Errors 419
The onerror event handler 419
The try...catch statement 423
Debugging Techniques 428
Using alerts 428
Using the Java console 429
Posting messages to the JavaScript console (Opera 7+ only) 430
Throwing your own errors 431
The JavaScript Verifier 432
Debuggers 432
Microsoft Script Debugger 432
Venkman – Mozilla’s debugger 435
Summary 443

Chapter 15: XML in JavaScript 445


XML DOM Support in Browsers 445
XML DOM support in IE 445
XML DOM support in Mozilla 450
Making interfaces play together 455
XPath Support in Browsers 465
Introduction to XPath 466
XPath support in IE 467
XPath support in Mozilla 467
XSLT Support in Browsers 471
XSLT support in IE 473
XSLT support in Mozilla 477
Summary 479

xvii
Contents
Chapter 16: Client-Server Communication 481
Cookies 481
Cookie ingredients 482
Other security restrictions 482
Cookies in JavaScript 483
Cookies on the server 485
Passing cookies between client and server 488
Hidden Frames 490
Using iframes 491
HTTP Requests 493
Using headers 495
Copycat implementations 496
Performing a GET request 496
Performing a POST request 497
LiveConnect Requests 498
Performing a GET request 498
Performing a POST request 500
Intelligent HTTP Requests 502
The get() method 502
The post() method 505
Practical Uses 506
Summary 507

Chapter 17: Web Services 509


A Quick Web Service Primer 509
What is a Web service? 509
WSDL 510
Web Services in Internet Explorer 513
Using the WebService component 513
WebService component example 515
Web Services in Mozilla 516
Enhanced privileges 517
Using the SOAP methods 518
Using WSDL proxies 522
A Cross-Browser Approach 525
The WebService object 525
The Temperature Service 527
Using the TemperatureService object 529
Summary 530

xviii
Contents

Chapter 18: Interacting with Plugins 531


Why Use Plugins? 531
Popular Plugins 532
MIME Types 533
Embedding Plugins 533
Including parameters 534
Netscape 4.x 534
Detecting Plugins 535
Detecting Netscape-style plugins 535
Detecting ActiveX plugins 540
Cross-browser detection 542
Java Applets 543
Embedding applets 543
Referencing applets in JavaScript 544
Writing applets 545
JavaScript-to-Java communication 546
Java-to-JavaScript communication 548
Flash Movies 551
Embedding Flash movies 552
Referencing Flash movies 552
JavaScript-to-Flash communication 553
Flash-to-JavaScript communication 555
ActiveX Controls 558
Summary 561

Chapter 19: Deployment Issues 563


Security 563
The Same Origin Policy 563
Window object issues 564
Mozilla-specific issues 566
Resource limitations 568
Internationalization Concerns 568
Detecting language using JavaScript 569
Strategies 569
String considerations 570
Optimizing JavaScript 573
Download time 573
Execution time 578

xix
Contents
Intellectual Property Issues 593
Obfuscating 593
Microsoft Script Encoder (IE only) 594
Summary 595

Chapter 20: The Evolution of JavaScript 597


ECMAScript 4 597
Netscape’s proposal 598
Implementations 604
ECMAScript for XML 605
Approach 605
The for each..in Loop 607
New classes 607
Implementations 616
Summary 616

Index 617

xx
Introduction

Although once supported by Netscape Enterprise Server and Active Server Pages (ASP) on the server,
JavaScript is primarily a client-side scripting language for use in Web browsers. Its main focus today is
to help developers interact with Web pages and the Web browser window itself.

JavaScript is very loosely based on Java, an object-oriented programming language popularized for use
on the Web by way of embedded applets. Although JavaScript has a similar syntax and programming
methodology, it is not a “light” version of Java. Instead, JavaScript is its own language, finding its home
in Web browsers around the world and enabling enhanced user interaction on Web sites and Web appli-
cations alike.

In this book, JavaScript is covered from its very beginning in the earliest Netscape browsers to the
present-day incarnations flush with support for XML and Web Services. You learn how to extend the
language to suit specific needs and how to create seamless client-server communication without inter-
mediaries such as Java or hidden frames. In short, you learn how to apply JavaScript solutions to
business problems faced by Web developers everywhere.

What Does This Book Cover?


Professional JavaScript for Web Developers provides a developer-level introduction along with the more
advanced and useful features of JavaScript.

Starting at the beginning, the book explores how JavaScript originated and evolved into what it is today.
A detailed discussion of the components that make up a JavaScript implementation follows, with spe-
cific focus on standards such as ECMAScript and the Document Object Model (DOM). The differences in
JavaScript implementations used in different popular Web browsers are also discussed.

Building on that base, the book moves on to cover basic concepts of JavaScript including its version of
object-oriented programming, inheritance, and its use in various markup languages such as HTML. An
in-depth examination of events and event handling is followed by an exploration of browser detection
techniques and a guide to using regular expressions in JavaScript. The book then takes all this knowl-
edge and applies it to creating dynamic user interfaces.

The last part of the book is focused on issues related to the deployment of JavaScript solutions in Web
applications. These topics include error handling, debugging, security, optimization/obfuscation, XML,
and Web Services.

xxi
Introduction

Who Is This Book For?


This book is aimed at three groups of readers:

❑ Experienced developers familiar with object-oriented programming who are looking to learn
JavaScript as it relates to traditional OO languages such as Java and C++.
❑ Web application developers attempting to enhance the usability of their Web sites and Web
applications.
❑ Novice JavaScript developers aiming to better understand the language.

In addition, familiarity with the following related technologies is a strong indicator that this book is
for you:

❑ XML
❑ XSLT
❑ Java
❑ Web Services
❑ HTML
❑ CSS

This book is not aimed at beginners lacking a basic computer science background or those looking to
add some simple user interactions to Web sites. These readers should instead refer to Wrox’s Beginning
JavaScript, Second Edition (Wiley Publishing, Inc., ISBN 0-7645-5587-1).

What You Need to Use This Book


To run the samples in the book, you need the following:

❑ Windows 2000, Windows Server 2003, Windows XP, or Mac OS X


❑ Internet Explorer 5.5 or higher (Windows), Mozilla 1.0 or higher (all platforms), Opera 7.5 or
higher (all platforms), or Safari 1.2 or higher (Mac OS X).

The complete source code for the samples is available for download from the Web site at
http://www.wrox.com/.

How Is This Book Structured?


1. What Is JavaScript?
This chapter explains the origins of JavaScript: where it came from, how it evolved, and what it
is today. Concepts introduced include the relationship between JavaScript and ECMAScript, the
Document Object Model (DOM), and the Browser Object Model (BOM). A discussion of the rele-
vant standards from the European Computer Manufacturer’s Association (ECMA) and the
World Wide Web Consortium (W3C) is also included.

xxii
Introduction
2. ECMAScript Basics
This chapter examines the core technology upon which JavaScript is built, ECMAScript. This
chapter describes the basic syntax and concepts necessary to write JavaScript code, from declar-
ing variables and functions to using and understanding primitive and reference values.

3. Object Basics
This chapter focuses on the foundations of object-oriented programming (OOP) in JavaScript.
Topics covered include defining custom objects using a variety of different methods, creating
object instances, and understanding the similarities and differences to OOP in JavaScript and Java.

4. Inheritance
This chapter continues the exploration of OOP in JavaScript, describing how inheritance works.
The various methods of achieving inheritance are discussed, and these methods are compared
and contrasted with inheritance in Java.

5. JavaScript in the Browser


This chapter explains how to include JavaScript in Web pages made with a variety of languages,
including Hyper Text Markup Language (HTML), Scalable Vector Graphics (SVG), and XML
User Interface Language (XUL). This chapter also introduces the Browser Object Model (BOM)
and its various objects and interfaces.

6. DOM Basics
This chapter introduces the DOM as implemented in JavaScript. It includes an introduction to
DOM concepts of specific value to Web developers. These concepts are applied later in exam-
ples using HTML, SVG, and XUL.

7. Regular Expressions
This chapter focuses on the JavaScript implementation of regular expressions, which are a pow-
erful tool for data validation and string manipulation. The origins of regular expressions are
explored, as well as its syntax and usage across a variety of programming languages. The chap-
ter ends with an explanation of the similarities and differences in JavaScript’s implementation.

8. Browser and Operating System Detection


This chapter explains the importance of writing JavaScript to run on a variety of Web browsers.
The two methods of browser detection, object/feature detection and user-agent string detection,
are discussed; the advantages and disadvantages of each approach are listed.

9. All about Events


This chapter discusses one of the most important concepts in JavaScript: events. Events are the
main way to tie JavaScript to a Web-user interface regardless of the markup language being
used. This chapter describes the various methods of handling events and the concept of event
flow (including bubbling and capturing).

10. Advanced DOM Techniques


This chapter introduces some of the more advanced features of the DOM, including ranges and
style-sheet manipulation. I give examples of when and how to use these technologies, and I also
discuss how to achieve cross-browser support given the differences in implementations.

xxiii
Another Random Document on
Scribd Without Any Related Topics
qualifications of Territorial electors. His dissent, at first, took the mild
form of a petition to Governor Reeder, after the election of
November 29, 1854. asking that "the entire vote of the districts
receiving the votes of citizens of Missouri, be set aside; or that the
entire election be set aside." After a brutal usurpation of the polls, at
the election for members of the Territorial Legislature, March 30,
1855, a Legislature which, under the organic act could determine
whether the State should be Free or Slave, Robinson again protested
and sought redress of the spoilation of the squatters' rights: and,
failing to obtain justice, united the Free-State men in a revolt against
the authority of the Territorial Legislature, and in a determination to
repudiate the laws it intended lawlessly to enact. Also, what had still
greater significance, he organized his followers into military
companies to resist, by force of arms, any further infringement upon
their rights. Answering his call to duty, the Free-State men of
Lawrence and vicinity led the nation in this crisis in public affairs,
making its history, and directing its destiny. It was the hour of
Destiny. Sending for a second consignment of Sharp's rifles,
Robinson wrote these impressive and heroic words:
We are in the midst of a revolution, as you will see by the papers.
How we shall come out of the furnace, God only knows. That we
have got to enter it, some of us, there is no doubt; but we are ready
to be offered.
In haste very respectfully, Yours, for freedom for a world,
C
.
R
o
b
i
n
s
o
n
.
The organization of a military force by the Free-State men, gave to
the Free-State party a solidarity and prestige it had not theretofore
enjoyed. It at once became a popular party; and encouraged by
daily accessions to its ranks by immigration, combined with a
prospective certainty of becoming the majority party, it became
bravely aggressive, and boldly launched its campaign for Free-State
supremacy. In furtherance of their plan of campaign, the Free-State
men adopted a constitution for a Free State, and organized and put
into effect a full fledged State Government in opposition to the
existing Territorial Government; and under it, with Charles Robinson
as Governor, sought admission into the Union. Only a wise and
courageous leadership combined with a high order of executive
ability, could successfully handle the delicate problems involved in
this complicated program. The leadership required the necessary
tact to unite and reconcile divergent convictions and opinions, within
the party, upon questions of principle as well as of policy; it also
required prudence to restrain the impetuous, and to avoid
complications which, at any time, might make shipwreck of the
cause.
The results accomplished by the Free-State settlers during the first
two years of their occupation of the Territory, amply justified the
generous congratulations in which they indulged. They had, wisely,
withdrawn from under the fire of an arrogant, domineering majority,
and, in their segregation, were surely creating a State to their own
liking, in their own way. They matched their wits against the
management of their political opponents, and were more than
satisfied with the dilemma in which the situation placed them. It
became plainly evident that unless the Free-State organizations, civil
and military, were utterly destroyed and further immigration from
the North retarded, the Free-State cause would certainly succeed.
The situation, therefore, demanded the adoption of more strenuous
methods in dealing with it than could be approved by the National
Administration.
What they had failed to accomplish by "peaceful" methods, the pro-
slavery junta now sought to gain by the execution of more radical
measures. They accordingly organized an "Army of Invasion," and
the Wakarusa War of 1855 became an historical incident. They
indicted the Free-State Governor, Robinson, and the more prominent
Free-State men, for "constructive" treason; arrested them, and put
them in prison. In May, 1856, under cover of judicial authority, the
town of Lawrence was looted and burned. The Free-State Legislature
that had been elected, assembled at Topeka, only to be dispersed,
July 4th, by the armed forces of the United States. A blockade of the
Missouri River was declared against Free-State immigrants, and
made effective. They also attempted, without success, to cut off
communications between Kansas and the Northern States, which the
Free-State men had opened up, via Iowa and Nebraska. They
murdered Dow, and Barber, and Brown, and Stewart, and Jones, and
Hoyt.
A third, and the final invasion, closed this chapter of heroic
undertakings and lamentable failures. September 14, 1856, their
army, 2800 strong, occupied Franklin. During the night, Lieutenant
Colonel Joseph E. Johnston, U. S. Army, with a battalion of cavalry
and a section of artillery, arrived at Lawrence. Placing his battery in
position on Mount Oread, the muzzles of his guns pointing toward
Franklin, and deploying his cavalry in the valley in front of the town,
he awaited the crisis developing in the pro-slavery situation. On the
morning of the 15th, the newly appointed Territorial Governor, John
W. Geary, accompanied by Lieutenant Colonel Philip St. George
Cooke, U. S. Army, arrived upon the scene from Lecompton. After a
short conversation with Governor Robinson, they rode out to
interview the invaders. It was the hour of fate. A brief conference
with General Atchison was held in front of Atchison's lines; and then,
it was all over; the Federal Government had intervened. The
campaign of violence had failed, and with it expired the last
substantial hope of the pro-slavery managers that the balance of
power between the warring sections of the country could be
restored. Upon receiving Governor Geary's ultimatum: that he must
retire with his forces from the Territory, immediately, Atchison turned
the head of his column toward Missouri. Arriving at Westport, he
disbanded his army and gave up the struggle. Buford returned to
Alabama and Jackson to Georgia. That Kansas would be a Free State
was practically assured from that hour.
Involved in the corollary of the Free-State victory were the startling
incidents in history that followed in quick succession, culminating in
the stupendous tragedies of war. Mr. F. B. Sanborn said:[79]
Had Kansas in the death struggle of 1856 fallen a prey to the slave
holders, slave-holding would today be the law of our imperial
democracy. The sanctions of the Union and the Constitution would
now be on the side of human slavery, as they were from 1840 to
1860.
The question of slavery domination must and will be fought out on
the plains of Kansas.[80]
Kansas must be a Slave State or the Union will be dissolved.... If
Kansas is not made a Slave State, it requires no sage to foretell that
there will never be another Slave State.[81]
Slavery in South Carolina is dependent upon its establishment in
Kansas.[82]
The Touch-stone of our political existence is Kansas.[83]
Georgia, Mississippi, and Alabama stand pledged to secede from the
Union, should Kansas applying for admission as a slave state be
refused admission.[84]
The question is one of life or death to the South upon the simple
alternative of the admission or rejection of Kansas with her slave
constitution.[85]
That American is little to be envied who can speak lightly of the
decisive contest in Kansas between the two antagonistic civilizations
of this continent. Either he does not love his country, or he is
incapable of understanding her history.[86]
CHAPTER IV
HIS PUBLIC SERVICES
Peace rules the day, where reason rules the mind.

—Collins
It was in the fall of 1855 that John Brown came to Kansas to try
another venture with fortune, in a new field of opportunity.
During the spring of 1854 his son John was seeking a new location,
and had written to his father in relation thereto; who replied to him
in a letter dated April 3, 1854, "I do not know of a good opening for
you this way."[87] But during the fall of that year five of Brown's sons
—John, Jason, Owen, Frederick, and Salmon—decided to settle in
Kansas. Having completed their arrangements they moved to the
Territory in the spring of 1855, arriving, about May 1st, in the vicinity
of Osawatomie. They were attracted to the Territory, as thousands of
others were, by the glowing accounts published by emigration
societies north and south. These prospectuses described the beauty
of the prairies, the fertility of the soil, the delightful and health-
giving climate; and set forth the prospective rewards in wealth,
health, and happiness which were awaiting all who took advantage
of the great opportunities the country offered. That they were not
disappointed upon their arrival, appears from their letters expressing
eminent satisfaction with everything pertaining to the settlement,
and their desire to have their father locate in Kansas with them.
May 24th John Brown, Jr., wrote to his father: "Salmon, Frederick,
and Owen say that they never was in a country that begun to please
them as well, and I will say that the present prospect for health,
wealth, and usefulness much exceeds even my most sanguine
anticipations. I know of no country where a poor man, endowed
with a share of common sense and with health, can get a start as
easy. If we can succeed in making this a free state, a great work will
be accomplished for mankind."[88]
Long before the coming of the Browns, the Free State leaders in the
Territory had determined to repudiate the laws enacted by the
Territorial Legislature; also, to defend themselves by force of arms
against the aggressions of their over-zealous pro-slavery neighbors
in Missouri. They had during April, 1855, secured from Boston a
hundred Sharp's rifles to arm the companies organized at Lawrence,
and were negotiating for further consignments of arms. After their
arrival in the Territory, the Browns realized the importance of this
movement, and since they had not brought any serviceable arms
with them—having come with axes instead of rifles—they wrote to
their father to try to get some for them, and bring them with him
when he came. The letter which John Brown, Jr., wrote to his father
on the subject is as follows:[89]
And now I come to the matter, that more than all else I intended
should be the principal subject of this letter. I tell you the truth when
I say, that while the interests of despotism has secured to its cause
hundreds and thousands of the meanest and most desperate of
men, armed to the teeth with Revolvers, Bowie Knives, Rifles and
Cannon—while they are not only thoroughly organized, but under
pay from Slaveholders—the friends of freedom are NOT ONE
FOURTH of them HALF ARMED, and as to MILITARY ORGANIZATION
among them it NO WHERE EXISTS IN THIS TERRITORY unless they
have recently done something in Lawrence. The result of this is that
the people here exhibit the most abject and cowardly spirit,
whenever their dearest rights are invaded and trampled down by the
lawless bands of Miscreants which Missouri has ready at a moment's
call to pour in upon them. This is the GENERAL effect upon the
people here so far as I have noticed, there are a few, and but a few
exceptions. Of course these foreign Scoundrels know what kind of
"ALLIES" they have to meet. They boast that they can obtain
possession of the polls in any of our election precincts without
having to fire a gun. I enclose a piece which I cut from a St. Louis
paper named the St. Louis Republican; it shows the spirit which
moves them. Now Missouri is not alone in the undertaking to make
this a Slave State. Every Slaveholding State from Virginia to Texas is
furnishing men and money to fasten Slavery upon this glorious land,
by means no matter how foul.
Now the remedy we propose is, that the Anti slavery portion of the
inhabitants should IMMEDIATELY, THOROUGHLY ARM and
ORGANIZE THEMSELVES in MILITARY COMPANIES. In order to effect
this, some persons must begin and lead in the matter. Here are 5
men of us who are not only anxious to fully prepare, but are
thoroughly determined to fight. We can see no other way to meet
the case. As in the language of the memorial lately signed by the
people here and sent to Congress petitioning help, "it is no longer a
question of negro slavery, but it is the enslavement of ourselves."
The General Government may be petitioned until the people here are
grey, and no redress will be had so long as it makes slavery its
paramount interest.... We have among us 5, 1 Revolver, 1 Bowie
Knife, 1 middling good Rifle, 1 poor Rifle, 1 small pocket pistol and 2
slung shot. What we need in order to be thoroughly armed for each
man, is 1 Colts large sized Revolver, 1 ALLEN & THURBER' RIFLE—
they are manufactured somewhere in Mass or Connecticut (Mr. Paine
of Springfield would probably know) and 1 heavy Bowie Knife—I
think the Minnie Rifles are made so that a sword bayonet may be
attached. With this we could compete with men who even possessed
Cannon. The real Minnie Rifle has a killing range almost equal to
Cannon and of course is more easily handled, perhaps enough so to
make up the difference. Now we want you to get for us these arms.
We need them more than we do bread. Would not Gerrit Smith or
someone, furnish the money and loan it to us for one, two or three
years, for the purpose until we can raise enough to refund it from
the Free soil of Kansas?...
In so far as the Brown family is concerned, this letter contains the
first recorded evidence of an intention, or of a desire of any of them
to actively oppose slavery in Kansas or elsewhere. It treats the
subject as an original proposition; as though it had never been
theretofore so much as mentioned in their family councils. The letter
has historical significance: it secured John Brown's introduction to
the public. It opened the way that enabled him to go to Kansas;
where he began a career which led, ultimately, to Harper's Ferry and
to Charlestown.
Following the suggestion of his son he took up with Gerrit Smith the
matter of securing a loan wherewith to purchase the arms desired.
The latter, instead of making an arrangement with them for the
necessary amount, personally presented the case before a
convention of Abolitionists that was held at Syracuse, New York,
June 28th, with the result that a collection was taken up which
yielded Brown sixty dollars in cash, twenty dollars of which was
given by Smith.
The success Brown met with in collecting funds "for the cause of
Kansas" at the Syracuse convention, opened before his commercial
vision that easy field for profitable enterprise, which he afterward
occupied and worked, in a professional manner, until the end of his
career. After the Syracuse meeting he began a system of personal
solicitations for money, arms, and clothing. At Akron, Ohio, he held
open meetings in one of the public halls of the village. Mr. Villard
says of these meetings:[90]
Because of their interest in the Kansas crisis, and in the Browns,
their former neighbors, the people were quickly roused by Brown's
graphic words, and liberally contributed arms of all sorts,
ammunition and clothing. Committees of Aid were appointed and ex-
Sheriff Lane was deputed to accompany Brown in a canvass of the
village shops and offices for contributions.
At Cleveland, also, he solicited aid with very satisfactory results. He
obtained there guns, revolvers, swords, powder, caps, and money.
He was so successful "that he thought it best to detain a day or two
longer on that account." Mr. Villard says, "He had raised nearly two
hundred dollars in that way in the two previous days, principally in
arms and ammunition."
Brown, with his son Oliver and his son-in-law, Henry Thompson, left
Chicago August 23d, on their journey to Kansas. Brown states that
before leaving he purchased "a nice young horse for $120 but have
so much load that we shall have to walk, a good deal." The journey
was accomplished without either accident or incident worthy of the
note, the party arriving at Osawatomie, October 6, 1855.
Brown himself, being very tired, did not cover the last mile or two
until the next day. They arrived in all but destitute condition, with
but sixty cents between them, to find the little family settlement in
great distress, not only because of the sickness already noted, but
because of the absence of any shelter save tents.[91]
At the time Brown arrived, the Free-State cause in the Territory was
well advanced and was progressing satisfactorily.
Out of all the meetings and conventions of the nine months after the
stolen March 30th election, there had come then, great gains to the
Free State Movement. The liberty party had been organized, leaders
had been developed, and a regular policy of resistance by legal and
constitutional measures adopted. If counsels of compromise were
still entirely too apparent, and too potent, the train of events which
resulted in Kansas's admission as a free State was well under way.
[92]
As a result of the measures that had been adopted, an election was
pending for the selection of a Free-State Territorial Delegate to
Congress; and delegates to a Free-State Constitutional Convention.
This election had been called by the Free-State men to be held
October 9th. The regular Territorial election had been held October
1st, the Free-State men not taking any part therein. Brown and his
sons attended the second, or Free-State election, October 9th.
An election is a political incident. A reference to an election by any
one invites an expression of his opinions upon the questions involved
in the election, if he have any special interest therein. Since Brown's
presence at this election was his introduction into the political affairs
of the Territory, we may reasonably conclude that his comments on
it cover the range of his general interest in the election and in the
issues involved therein. His letters to his family in the East
announcing his arrival at his destination, and describing the
condition of affairs, domestic as well as political, are herewith
republished.
O
s
a
w
a
t
o
m
i
e
,
K
.
T
.
O
c
t
.
1
3
,
1
8
5
5
.
S
a
t
u
r
d
a
y
E
v
e
.
Dear Wife and Children, Every One—We reached the place where the
boys are located one week ago, late at night; at least Henry and
Oliver did. I, being tired, stayed behind in our tent, a mile or two
back. As the mail goes from here early Monday morning, we could
get nothing here in time for that mail. We found all more or less sick
or feeble but Wealthy and Johnny. All at Brownsville appear now to
be mending, but all sick or feeble here at Mr. Adair's. Fever and ague
and chill-fever seem to be very general. Oliver has had a turn of the
ague since he got here, but has got it broken. Henry has had no
return since first breaking it. We met with no difficulty in passing
through Missouri, but from the sickness of our horse and our heavy
load. The horse has entirely recovered. We had, between us all, sixty
cents in cash when we arrived. We found our folks in a most
uncomfortable situation, with no houses to shelter one of them, no
hay or corn fodder of any account secured, shivering over their little
fires, all exposed to the dreadful cutting winds, morning and evening
and stormy days. We have been trying to help them all in our power,
and hope to get them more comfortable soon. I think much of their
ill health is owing to most unreasonable exposure. Mr. Adair's folks
would be quite comfortable if they were well. One letter from wife
and Anne to Salmon, of August 10, and one from Ruth to John, of
19th September, is all I have seen from any of you since getting
here. Henry found one from Ruth which he has not shown me. Need
I write that I shall be glad to hear from you? I did not write while in
Missouri, because I had no confidence in your getting my letters. We
took up little Austin and brought him on here, which appears to be a
great comfort to Jason and Ellen. We were all out a good part of the
last night, helping to keep prairie fire from destroying everything; so
that I am almost blind today, or I would write you more.
S
a
b
b
a
t
h
E
v
e
,
O
c
t
o
b
e
r
1
4
.
I notice in your letter to Salmon your trouble about the means of
having the house made more comfortable for winter, and I fondly
hope you have been relieved on that score before now, by funds
from Mr. Hurlbut, of Winchester, Conn., from the sale of the cattle
there. Write me all about your situation; for, if disappointed from
that source, I shall make every effort to relieve you in some other
way. Last Tuesday was an election day with Free State men in
Kansas, and hearing that there was a prospect of difficulty we all
turned out most thoroughly armed (except Jason, who was too
feeble); but no enemy appeared, nor have I heard of any
disturbance in any part of the Territory. Indeed, I believe Missouri is
fast becoming discouraged about making Kansas a slave State, and I
think the prospect of its becoming free is brightening every day. Try
to be cheerful, and always "hope in God," who will not leave nor
forsake them that trust in him. Try to comfort and encourage each
other all you can. You are all very dear to me, and I humbly trust we
may be kept and spared to meet again on earth; but if not, let us all
endeavor earnestly to secure admission to that eternal home, where
will be no more bitter separations, "where the wicked shall cease
from troubling and the weary be at rest." We shall probably spend a
few days more in helping the boys to provide some kind of shelter
for winter, and mean to write you often. May God in infinite mercy
bless, comfort, and save you all, for Christ's sake!
Y
o
u
r
A
f
f
e
c
t
i
o
n
a
t
e
h
u
s
b
a
n
d
a
n
d
f
a
t
h
e
r,
J
o
h
n
B
r
o
w
n
.
In simple language and at considerable length. Brown thus
announced his arrival at his destination, and described the
conditions prevailing in Kansas and in the Brown colony. A half dozen
lines in this letter sufficed to relate the incident of the important
election of October 9th, and to give his opinions of the vital
questions involved in the political situation as it then appeared to
him. These lines are void of any hostile word or phrase; also they
are void of any sentiment that can be made to suggest that Brown
was different from the ordinary immigrant that came from the North
to found a home and help to make a Free State. No settler from the
North ever wrote a letter less war-like or more peaceful and
domestic in its character than this letter written by John Brown. The
clause, "I think the prospect of its becoming free is brightening
every day," is a truer index to the state of Brown's mind, and is
better evidence of the peaceful character of his quest in Kansas,
than the combined reckless assertions of his biographers to the
contrary.
In violence of contemporary evidence, all of his biographers and
some of the historians have sought to educate the public to believe
that Brown came to Kansas on a hostile mission. The public has
been led to accept the fictitious John Brown, the picturesque
character of history, instead of the real man under consideration. To
this character constructing propaganda Mr. Redpath was an ardent
contributor. One of his many effective flights has reference to the
letter, heretofore published, which his son John wrote May 24th. He
said concerning it:
He undoubtedly regarded it as a call from the Almighty to gird up his
loins and go forth to do battle "as the warrior of the Lord" as "the
warrior of the Lord against the Mighty" in behalf of His despised
poor and His downtrodden people. The moment long waited for had
at length arrived; the sign he had patiently expected had been
given; and the brave old soldier of the God of Battles prepared at
once, to obey the summons.... John Brown did not go to Kansas to
settle there. He did not dare to remain tending sheep at North Elba
when the American Goliath and his hosts were in the field, defying
the little armies of the living Lord.[93]
While Mr. Redpath did very well, his panegyric is not comparable
with some of the latest and more scholarly studies of Brown. Here is
one of Mr. Villard's efforts:
Thenceforth John Brown could give free rein to his wanderlust; the
shackles of business life dropped from him. He was now bowed and
rapidly turning gray; to everyone's lips the adjective "old" leaped as
they saw him. But this was not the age of senility, nor of weariness
with life; nor were the lines of care due solely to family and business
anxieties or to the hard labor of the fields. They were rather the
marks of the fires consuming within; of the indomitable purpose that
was the main spring of every action; of a life devoted, a spirit
inspired. Emancipation from the counter and the harrow came
joyfully to him at the time of life when most men begin to long for
rest and the repose of a quiet, well ordered home. Thenceforth he
was free to move where he pleased, to devote every thought to his
battle with the slave-power he staggered, which then, knew nothing
of his existence.
The metamorphosis was now complete. The staid, sombre merchant
and patriarchal family-head was ready to become Captain John
Brown of Osawatomie, at the mere mention of whose name Border
Ruffians and swashbuckling adherents to the institution of slavery
trembled and often fled. Kansas gave John Brown the opportunity to
test himself as a guerrilla leader for which he had longed; for no
other purpose did he proceed to the Territory; to become a settler
there as he had hoped to in Virginia in 1840 was furthest from his
thoughts.[94]
At the time the chrysalis of the Osawatomie guerilla is said to have
emancipated himself bodily from the harrow and was burning to take
up arms against the "swashbucklers," he wrote a letter to his son
Salmon concerning his intentions to join the colony and asked him
some questions relating to their condition, and to their requirements.
Strange as it may seem this letter contained nothing that called for a
war-like, or even a moderately ferocious reply from Salmon. His
answer to it is scarcely dramatic; in fact it seems to relate more to
the harrow, and to such disinteresting sublunary topics as the
condition of his simple but more or less dilapidated wardrobe, than it
does to "indomitable purposes" or to armies of a Lord who Mr.
Redpath represents as being still alive. He wrote, June 22d:[95]
In answer to your questions about what you will need for your
company, I would say that I have an acre of corn that looks very
well, and some beans and squashes and turnips. You will want to
get some pork and meal, and beans enough to last till the crop
comes in, and then I think we will have enough grain to last through
the winter. I will have a house up by the time you get here. My
boots are very near worn out, and I shall need some summer pants
and a hat. I bought an ax and that you will not have to get.
In a series of thirty-eight letters, published in Mr. Sanborn's Life and
Letters of John Brown, commencing with the date, January 18,
1841; and ending with the letter herein, of October 14, 1855, there
is not an expression relating to slavery that has not been heretofore
quoted or referred to in this work. That Mr. Sanborn was a partisan
writer, and that he sifted Brown's correspondence in a search for
letters which could be quoted in support of the assumptions of these
and other panegyrists, concerning his alleged hostility to slavery, will
not be denied. Their assumptions are therefore, wholly fanciful;
there is not a sentence contained in any of these letters, that can be
quoted in justification of them. The attributes put forth in these
eulogies are not only gratuitous, but they are illogical and
inconsistent with Brown's circumstances, and incompatible with his
environment. Mrs. Anne Brown Adams in a few plain words told why
John Brown went to Kansas. She said:
Father said his object in going to Kansas was to see if something
would not turn up to his advantage.[96]
The often repeated statement that Brown came to Kansas "to fight,"
and not "to settle" after the manner of other immigrants, is further
discredited in this history.
Before the Mason Committee, in January, 1860, Mr. Wm. F. Arny,
who knew Brown to have been a non-resistant, testified that he had
conversed with him in Kansas, in 1858; and that he, on that
occasion, asked him "how he reconciled his opinions then, with the
peace principles which he held when he knew him in Virginia twenty
years before. To this Brown replied, that the 'aggressions of slavery,
the murders and robbery perpetrated upon himself and members of
his family, the lawlessness by Atchison and others in 1855 and from
that time down to the Marais-des-Cygnes, convinced him that peace
was but an empty word.'"[97]
Before the same committee Mr. Augustus Wattles testified:[98]
Captain Brown told me that he had no idea of fighting until he heard
the Missourians, during the winter he was there, make arrangements
to come over into the Territory to vote. He said to me that he had
not come to Kansas to settle himself, having left his family at North
Elba, but that he had come to assist his sons in their settlement and
to defend them, if necessary, in a peaceable exercise of their political
rights.
Writing to his wife February 1, 1856, Brown said:
The idea of again visiting those of my dear family at North Elba is so
calculated to unman me, that I seldom allow my thoughts to dwell
upon it.
This language bears the interpretation that he had located with the
other members of his family in Kansas, and that a return to North
Elba would be in the nature of a visit.
Brown told Mr. Arney that it was his intention, originally, to settle in
Kansas. In his testimony before the Mason Committee, he said: "He
(Brown) then referred to the fact that he had sent his sons into the
Territory of Kansas in 1853 or 1854 with a lot of blooded cattle and
other stock with the intention of settling."[99] There is presumptive
evidence too, that he did "settle" in Kansas and that he did take a
claim; also that it was "jumped." In a letter to Brown dated June 24.
1857, the late Wm. A. Phillips wrote as follows:[100] "Your old claim I
believe, has been jumped. If you do not desire to contest it, let me
suggest that you make a new settlement at some good point of
which you will be the head. Lay off a town and take claims around
it."
Among the real conditions of poverty described by Brown in his
letters of October 13th and 14th, and with but "sixty cents" in his
pocket, it is irrational to assume that he was free to move "where he
pleased" or that he was "free to devote every thought," or any of his
thoughts, for that matter, to this "battling" business. He was not
"emancipated from the counter and the harrow," and from his
natural obligation to continue to provide for the dependent wife and
children, who were suffering the acute privations of poverty in a
miserable home. The letters quoted are evidence of the domestic
character of the thoughts which occupied his mind, and of his deep
solicitude for the wants of his family. They are earnest letters,
written about the pressing affairs of his domestic life, by a man of
more than ordinary experience. He dismisses any reference to the
subject of the "driving force of a mighty and unselfish purpose," with
the moderate and sensible opinion, that the "prospect of Kansas
becoming a Free state is brightening every day."
November 2, 1855, Brown wrote a long and interesting letter to his
wife about affairs in their Kansas home, concluding with this very
conservative and peaceful statement: "I feel more and more
confident that slavery will soon die out here,—and to God be the
praise."[101] The letter is as follows:
B
r
o
w
n
s
v
il
l
e
,
K
.
T
.,
N
o
v
.
2
,
1
8
5
5
.
Dear Wife and Children, Every One—
I feel grateful to learn that you were all then well, and I think I fully
sympathize with you in all the hardships and discouragements you
have to meet; but you may be assured you are not alone in having
trials. I believe I wrote you that we found everyone here more or
less unwell but Wealthy and Johnny, without any sort of a place
where a stout man even could protect himself from the cutting, cold
winds and storms, which prevail here, much more than in any place
where we have ever lived; and no crops of hay or anything raised
had been taken care of; with corn wasting by cattle and horses,
without fences; and, I may add without any meat; and Jason's folks
without sugar, or any kind of bread stuffs but corn ground with great
labor in a hand-mill about two miles off. Since I wrote you before,
Wealthy, Johnny, Elen and myself have escaped being sick. Some
have had the ague, but lightly; but Jason and Oliver have had a hard
time of it and are yet feeble. Under existing circumstances, we have
made but little progress; but we have made a little. We have got a
shanty three logs high, chinked and mudded and roofed with our
tent; and a chimney so far advanced that we can keep a fire in it for
Jason. John has his shanty a little better fixed than it was, but
miserable enough now; and we have got their little crop of beans
secured, which, together with johnny cake, mush and milk,
pumpkins and squashes, constitute our fare. Potatoes they have
none of any account; milk, beans, pumpkins and squashes, a very
moderate supply just for the present use. We have also got a few
house logs cut for Jason. I do not send you this account to render
you more unhappy but merely to let you know that those here are
not altogether in paradise, while you have to stay in that miserable
frosty region.... I feel more and more confident that slavery will soon
die out here.—and to God be the praise!...
November 23d, he wrote:
Since Watson wrote, I have felt a great deal troubled about your
prospects for a cold house to winter in, and since I wrote last, I have
thought of a cheap, ready way to help it much. Take any common
straight-edged boards, and run them from the ground up to the
eaves, barn fashion, not driving the nails in so far but that they may
easily be drawn, covering all but doors and windows, as close as
may be in that way, and breaking joints if need be. This can be done
by any one and in any weather not very severe, and the boards may
afterwards mostly be saved for other uses. I think much too, of your
widowed state, and I sometimes allow myself to dream a little of
again sometime enjoying the comforts of a home; but I do not dare
to dream much....
There were no disturbances in the Territory until the latter part of
November, when the "Wakurusa War" became imminent. On the
27th the following dispatch was sent from Westport:
Hon. E. C. McLaren, Jefferson City—Governor Shannon has ordered
out the militia against Lawrence. They are now in open rebellion
against the laws. Jones is in danger.
December 6th, notice was sent out to all Free-State men to come to
Lawrence. John Brown, with others from the vicinity of Osawatomie,
answered the call, and upon their arrival at Lawrence he was
appointed a captain in the Fifth Regiment, Kansas Volunteers. The
men from Brown's neighborhood were assigned to his company
which was named the "Liberty Guards."
There has been much controversy concerning Brown's actions during
this brief but very interesting campaign; due, in some instances,
perhaps, to political contention, but principally to the efforts of his
biographers and eulogists to make him appear as a conspicuous
figure in the proceedings, the hero of the occasion. However,
Brown's plain sensible letter, written to his wife at the time, giving
her a full and interesting account of what occurred, will be accepted
by all sane persons, as evidence of what did occur, as well as
evidence of his personal opinions of all matters pertaining thereto,
so far as they came under his observation. His letter is as follows:
[102]

O
s
a
w
a
t
o
m
i
e
,
K
.
T
.,
D
e
c
.
1
6
,
1
8
5
5
.

S
a
b
b
a
t
h
E
v
e
n
i
n
g
.
Dear Wife and Children, Every One—I improve the first mail since my
return from the camp of volunteers, who lately turned out for the
defense of the town of Lawrence in this Territory, and
notwithstanding, I suppose you have learned the result before this,
(possibly), I will give a brief account of the invasion in my own way.
About three or four weeks ago news came that a Free-State man by
the name of Dow had been murdered by a pro-slavery man by the
name of Coleman, who had gone and given himself up for trial to
the pro-slavery Governor Shannon. This was soon followed by
further news that a Free State man, who was the only reliable
witness against the murderer had been seized by a Missourian
(appointed sheriff by the bogus Legislature of Kansas) upon false
pretexts, examined, and held to bail under such heavy bonds, to
answer to those false charges, as he could not give; that while on
his way to trial, in charge of the bogus sheriff, he was rescued by
some men belonging to a company near Lawrence; and that in
consequence of the rescue. Governor Shannon had ordered out all
the pro-slavery force he could muster in the Territory, and called on
Missouri for further help; that about two thousand had collected,
demanding a surrender of the rescued witness and of the rescuers,
the destruction of several buildings and printing-presses and a giving
up of the Sharpe's rifles by the Free-State men,—threatening to
destroy the town with cannon, with which they were provided, etc.;
that about an equal number of Free-State men had turned out to
resist them, and that a battle was hourly expected or supposed to
have been already fought.
These reports appeared to be well authenticated, but we could get
no further account of matters; and I left this for the place where the
boys are settled, at evening, intending to go to Lawrence to learn
the facts the next day. John was, however, started on horseback, but
before he had gone many rods, word came that our help was
immediately wanted. On getting this last news, it was at once
agreed to break up at John's camp, and take Wealthy and Johnny to
Jason's camp (some two miles off), and that all the men but Henry,
Jason, and Oliver should at once set off for Lawrence under arms;
those three being wholly unfit for duty. We then set about providing
a little corn-bread and meat, blankets, and cooking utensils, running
bullets and loading all our guns, pistols, etc. The five set off in the
afternoon and after a short rest in the night (which was quite dark),
continued our march until after daylight next morning, when we got
our breakfast, started again, and reached Lawrence in the forenoon,
all of us more or less lamed by our tramp. On reaching the place, we
found that negotiations had commenced between Governor Shannon
(having a force of some fifteen or sixteen hundred men) and the
principal leaders of the Free-State men, they having a force of some
five hundred men at that time. These were busy, night and day,
fortifying the town with embankments and circular earthworks, up to
the time of the treaty with the Governor, as an attack was constantly
looked for, notwithstanding the negotiations then pending. This state
of things continued from Friday until Sunday evening. On the
evening we left Osawatomie, a company of the invaders, of from
fifteen to twenty-five attacked some three or four Free-State men,
mostly unarmed, killing a Mr. Barber from Ohio, wholly unarmed. His
body was afterward brought in and lay for some days in the room
afterwards occupied by a part of the company to which we belong (it
being organized after we reached Lawrence). The building was a
large unfinished stone hotel, in which a great part of the volunteers
were quartered, who witnessed the scene of bringing in the wife and
other friends of the murdered man. I will only say of this scene that
it was heart-rending, and calculated to exasperate the men
exceedingly, and one of the sure results of civil war.
After frequently calling on the leaders of the Free-State men to come
and have an interview with him, by Governor Shannon, and after as
often getting for an answer that if he had any business to transact
with any one in Lawrence, to come and attend to it, he signified his
wish to come into the town, and an escort was sent to the invaders'
camp to conduct him in. When there, the leading Free-State men,
finding out his weakness, frailty, and consciousness of the awkward
circumstances into which he had really got himself, took advantage
of his cowardice and folly and by means of that and the free use of
whiskey and some trickery succeeded in getting a written
arrangement with him much to their own liking. He stipulated with
them to order the pro-slavery men of Kansas home, and to proclaim
to the Missouri invaders that they must quit the Territory without
delay, and also to give up General Pomeroy (a prisoner in their
camp),—which was all done; he also recognizing the volunteers as
the militia of Kansas, and empowering their officers to call them out
whenever in their discretion the safety of Lawrence or other portions
of the Territory might require it to be done. He (Governor Shannon)
gave up all pretension of further attempt to enforce the enactment
of the bogus Legislature, and retired, subject to the derision and
scoffs of the Free-State men (into whose hands he had committed
the welfare and protection of Kansas), and to the pity of some, and
the curses of others of the invading force.
So ended this last Kansas invasion—the Missourians returning with
flying colors, after incurring heavy expenses, suffering great
exposure, hardships, and privations, not having fought any battles,
burned or destroyed any infant towns or Abolition presses; leaving
the Free-State men organized and armed, and in full possession of
the Territory; not having fulfilled any of all their dreadful
threatenings, except to murder one unarmed man, and to commit
some robberies and waste of property upon defenseless families,
unfortunately within their power. We learn by their papers that they
boast of a great victory over the Abolitionists; and well they may.
Free-State men have only hereafter to retain the footing they have
gained, and Kansas is free. Yesterday the people passed upon the
Free-State constitution. The result, though not yet known, no one
doubts....
We have received fifty dollars from father, and learned from him that
he has sent you the same amount,—for which we ought to be
grateful, as we are much relieved, both as respects ourselves and
you....
This letter will always stand in its completeness as an official
expression by John Brown of his entire satisfaction with everything
that was done by the Free-State men on this occasion. The
stipulations contained in the peace treaty not only covered every
point for which the Free-State men were contending, but gave them
official recognition, in Territorial affairs, with authority therein far
greater than they could have hoped to obtain. Brown's entire
approval of the agreement, without any reservation whatever, is
clearly and fully expressed in the sentence:
Free-State men have only hereafter to retain the footing they have
gained and Kansas is free.
No language could make his approval of what had been done more
complete or specific; and yet, notwithstanding this unequivocal
record, by Brown himself, of his approval of what had been done, his
biographers insist that he was not only dissatisfied with the
proceedings that were had, but that "the peace treaty itself
produced in him only anger when he first heard of it."
John Brown, boiling over with anger, mounted the shaky platform
and addressed the audience when Robinson had finished. He
declared that Lawrence had been betrayed, and told his hearers that
they should make a night attack upon the pro-slavery forces and
drive them from the territory. "I am an Abolitionist," he said, "dyed
in the wool," and then he offered to be one of ten men to make a
night attack upon the Border Ruffian camp. Armed, and with
lanterns, his plan was to string his men along the camp far apart. At
a given signal in the early morning hours, they were to shout and
fire on the slumbering enemy.[103]
That this speech will stand for all time, as a classic in the existing
melodramatic literature of John Brown, will be conceded. The novel
plan of a night attack by ten men, furnished with lanterns, as
targets, "strung far apart," against a force of fifteen hundred men,
will, of itself, commend it to such recognition.
A summary of the speeches, recently referred to as "harangues,"
made by Governor Shannon, and by General Lane, and by Charles
Robinson, on this occasion, was duly reported at the time and
published throughout the country, for this was a notable incident in
our national history. But not a word was reported about Brown's
speech. It ought to have been the climax—the fire-works—of the
whole performance for he was the only one of the speakers who is
said to have been "boiling over" with anything. It may be assumed
however that if John Brown had made a violent speech from this
platform on this occasion, the fact would have been reported by the
reporter for the Herald of Freedom, who was present, and who felt
very kindly toward him. It may be true that Brown did some
grumbling in camp, or some loud talking somewhere, about the
treaty which he may not have understood at the time.
A very extended report of the incidents occurring in the "Wakurusa
War" is contained in the Lawrence Herald of Freedom of December
15, 1855,[104] from which the following are extracts:
Sunday the negotiations were resumed with Governor Shannon and
finally completed, the substance of which was communicated to the
people by the Governor. The settlement was received with
satisfaction and yet the terms were not coincided in so fully as many
supposed it would be. It was apparent that the Governor was in bad
odor, as several attempts to get up cheers in his favor proved a
failure, though no insult was shown him.
Colonel Lane followed and was loudly cheered. He assured the public
there had been no concession of honor and that the people of
Lawrence and Kansas, would cheerfully acquiesce in the terms of the
settlement as soon as they could learn the particulars....
General Robinson was also loudly cheered and congratulated by the
people on account of the settlement.... The day closed by Governor
Shannon giving General Robinson and Colonel Lane each a
commission, and clothing them with full power to preserve the peace
in the vicinity and to use the volunteer force at their command for
that purpose.
Tuesday was full of animation. The soldiers were reviewed and
finally formed in a square and addressed by the commanding
officers. General Lane spoke as follows:...
At the close of General Lane's speech, he was vociferously cheered.
General Robinson, as Commander in Chief, delivered the following
speech which was loudly applauded. He said: "...The moral strength
of our position is such that even the 'gates of hell' could not prevail
against us, much less a foreign mob and we gained a bloodless
victory."... As General Robinson closed, six cheers were given to him.
Even a reporter and journalist so enterprising as James Redpath
failed to know of Brown's much advertised speech. He said:[105]
I had no personal knowledge of his opposition to the Treaty of
Peace.... The first time I heard of old Brown was in connection with
a caucus at the town of Osawatomie.
It was not Redpath's fault that he did not then know John Brown or
that he had not even heard of him. It was simply because Brown
was an ordinary person, and had not done anything yet to attract
public attention to his personality. Opportunity did not happen to
knock at his door on that occasion; if it had, Brown, doubtless,
would have acquitted himself creditably, and Mr. Redpath would have
heard of him. As soon as Brown did even a little thing, Redpath
heard of it promptly. April 16, 1856, a meeting or caucus was held at
Osawatomie to consider the question of paying the taxes that had
been levied by authority of the Territorial Legislature, and other
public measures. To pay the taxes would be a recognition of the
"Bogus Legislature" that had enacted the laws relating to taxation.
Richard Mendenhall was chairman of the meeting and Oscar V.
Dayton was secretary. Brown, among others, spoke in opposition to
paying the taxes. There was nothing sensational in this incident, but
Redpath heard of the meeting and located Brown in his mind,
because of it. Referring to the incident Mr. Redpath made this
authoritative statement:[106] "This was John Brown's first and last
appearance in a public meeting in Kansas." Therefore, it appears
that Mr. Villard has been imposed upon.
Of Brown himself, the Herald published the following sane and
restful paragraph:
About noon Mr. John Brown, an aged gentleman from Essex County,
New York, who has been a resident of the Territory for several
months, arrived with four of his sons,—leaving several others at
home sick, bringing a quantity of arms with him which were placed
in his hands by eastern friends for the defense of the cause of
freedom. Having more than he could well use to advantage, a
portion of them were placed in the hands of those who were more
destitute. A company was organized and the command given to Mr.
Brown for the zeal he had exhibited in the cause of freedom, both
before and after his arrival in the Territory.[107]
Brown, with his sons, returned to their homes December 14th, and
under that date, in a letter to Orson Day, he expressed, further, his
satisfaction with what had been accomplished at Lawrence by the
Free-State managers. He said: "The Territory is now entirely in the
power of the Free-State men," and stated hopefully his opinion that
"the Missourians will give up all further hope of making Kansas a
slave state."[108] January 1, 1856, he wrote from West Point,
Missouri: "In this part of the state there seems to be but little feeling
on the slave question."[109]
January 5th, a Free-State county convention was held at
Osawatomie to nominate candidates for members of the Free-State
Legislature. The Browns took a prominent part in the proceedings.
John Brown was chairman of the meeting. Frederick Brown received
the nomination for member of the House of Representatives, but at
the request of his father, he declined the nomination, and it was
given to John Brown, Jr.
With his participation in this convention, John Brown closed his
public services. Later—probably during March—he abandoned his
honorable commission as captain of the "Liberty Guards," disbanded
the company, and with his sons, Owen, Salmon, Frederick, Oliver,
and his son-in-law, Henry Thompson, planned and decided to
abandon the Free-State cause, enter upon a career of crime, and
leave the neighborhood. The course was agreed upon with John
Brown, Jr., as accessory thereto; but not with the knowledge of
Jason Brown. These men comprised John Brown's "little company of
six" who, with others, committed the robbery on the Pottawatomie
on the night of May 24th—a robbery that included in the plans for its
execution, the murder of seven persons, five of whom fell beneath
the blows of the assassins.
CHAPTER V
ROBBERY AND MURDER ON THE
POTTAWATOMIE
A blush as of roses
Where rose never grew!
Great drops on the bunch-grass
But not of the dew!
A taint in the sweet air
For wild bees to shun!
A stain that will never
Bleach out in the sun!

Back, steed of the prairies!


Sweet song bird, fly back!
Wheel hither, bald vulture!
Gray wolf, call thy pack!
The foul human vultures
Have feasted and fled;
The wolves of the Border
Have crept from the dead.

—From Le Marais du Cygne. Whittier.

From a rude home in the bleak mountains of northern New York,


John Brown went to Kansas; not for the purpose of fighting, but
inspired by the hope of bettering his shattered fortunes; a hope that
withered in the budding, and gave place to feelings of deep
disappointment and discouragement. He wrote February 1st:
It is now nearly six weeks that the snow has almost constantly been
driven, like dry sand, by the fierce winds of Kansas. By means of the
sale of our horse and wagon, our present wants are tolerably well
met; so that, if health is continued to us, we shall not probably
suffer much.... Thermometer on Sunday and Monday at twenty-eight
to twenty-nine below zero. Ice in the river, in the timber, and under
the snow, eighteen inches thick this week.... Jason down again with
the ague, but he was some better yesterday. Oliver was also laid up
by freezing his toes,—one great toe so badly frozen that the nail has
come off. He will be crippled for some days yet. Owen has one foot
frozen. We have middling tough times (as some would call them) but
have enough to eat, and abundant reason for the most unfeigned
gratitude....[110]
These were hard conditions. It would be difficult to imagine
circumstances of greater discomfort and hopelessness. But what
about the future—the future for himself and for the wife and the
daughters depending upon him for the necessaries of life, for whose
benefit he had come to Kansas? Did Brown think of them? Present
inconvenience and privation may be borne with fortitude if the future
holds out a promise of betterment. In his case we may reasonably
assume that the problems of the future, rather than the present
conditions and discouragements, engrossed his thoughts. It is
altogether unreasonable to suppose that this unscrupulous man of
affairs—this restless, aggressive speculator—sat listlessly, amid his
environment of discomfort and poverty, and permitted the dreary
months to pass without thinking of his precarious financial condition,
and of the incessantly urgent family responsibilities impending; and
of the possibilities of bettering his fortunes in the immediate future.
His biographers have wisely avoided discussion of the practical side
of Brown's condition at this time, preferring to wander in more
intangible fields, and to speculate upon the emotional and
metaphysical phenomena they seek to involve in the situation. The
record of his life at this time, however, reveals the fact that Brown
did think of the future and of its responsibilities; and that he did
mature a plan to better his financial condition. Also, that his plan
was in harmony with his latest and best biographer's estimate of his
character: "It was not only that he was visionary as a business
man,"[111] says Mr. Villard, "but that he developed the fatal tendency
to speculate; doubtless the outgrowth of his restlessness, and the
usual desire of the bankrupt for a sudden coup to restore his
fortune," To his wife he wrote as follows:
B
r
o
w
n
'
s
S
t
a
t
i
o
n
,
K
.
T
.,
A
p
r
il
7
,
1
8
5
6
.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like