(Ebook) JavaScript and DHTML cookbook by Danny Goodman ISBN 9780596514082, 0596514085 - The ebook is available for online reading or easy download
(Ebook) JavaScript and DHTML cookbook by Danny Goodman ISBN 9780596514082, 0596514085 - The ebook is available for online reading or easy download
https://ebooknice.com/product/javascript-bible-922374
https://ebooknice.com/product/javascript-bible-922372
https://ebooknice.com/product/javascript-bible-976386
https://ebooknice.com/product/javascript-bible-976388
(Ebook) JavaScript Bible, 7th edition (2010) by Danny Goodman, Michael
Morrison, Paul Novitski, Tia Gustaff Rayl ISBN 9780470526910,
0470526912
https://ebooknice.com/product/javascript-bible-7th-
edition-2010-2030870
https://ebooknice.com/product/learning-the-iphone-sdk-for-javascript-
programmers-create-native-apps-with-objective-c-and-xcode-1527026
(Ebook) DHTML Utopia: Modern Web Design Using JavaScript & DOM by
Stuart Langridge ISBN 9780957921894, 0957921896
https://ebooknice.com/product/dhtml-utopia-modern-web-design-using-
javascript-dom-978710
https://ebooknice.com/product/danny-goodman-s-applescript-
handbook-990640
JavaScript & DHTML Cookbook ™
Other resources from O’Reilly
Related titles Adding Ajax HTML & XHTML: The
CSS Cookbook™ Definitive Guide
CSS: The Definitive Guide JavaScript: The Definitive
Dynamic HTML: The Defini- Guide
tive Reference Learning JavaScript
Danny Goodman
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (safari.oreilly.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or [email protected].
Printing History:
April 2003: First Edition.
August 2007: Second Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. The Cookbook series designations, JavaScript and DHTML Cookbook, the image of
a howler monkey, and related trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the use of the information
contained herein.
ISBN-10: 0-596-51408-5
ISBN-13: 978-0-596-51408-2
[M]
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
1. Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Concatenating (Joining) Strings 4
1.2 Improving String Handling Performance 6
1.3 Accessing Substrings 7
1.4 Changing String Case 8
1.5 Testing Equality of Two Strings 9
1.6 Testing String Containment Without Regular Expressions 11
1.7 Testing String Containment with Regular Expressions 13
1.8 Searching and Replacing Substrings 14
1.9 Using Special and Escaped Characters 15
1.10 Reading and Writing Strings for Cookies 17
1.11 Converting Between Unicode Values and String Characters 20
1.12 Encoding and Decoding URL Strings 21
1.13 Encoding and Decoding Base64 Strings 23
v
2.10 Calculating a Previous or Future Date 43
2.11 Calculating the Number of Days Between Two Dates 45
2.12 Validating a Date 47
vi | Table of Contents
5.9 Detecting Object Property and Method Support 124
5.10 Detecting W3C DOM Standard Support 126
5.11 Detecting the Browser Written Language 127
5.12 Detecting Cookie Availability 128
5.13 Defining Browser- or Feature-Specific Links 129
5.14 Testing on Multiple Browser Versions 130
Table of Contents | ix
13.8 Determining the Location of a Nonpositioned Element 414
13.9 Animating Straight-Line Element Paths 415
13.10 Animating Circular Element Paths 419
13.11 Creating a Draggable Element 421
13.12 Scrolling div Content 426
13.13 Creating a Custom Scrollbar 432
13.14 Creating a Slider Control 445
x | Table of Contents
15.8 Displaying the Number of Days Before Christmas 525
15.9 Displaying a Countdown Timer 527
15.10 Creating a Calendar Date Picker 534
15.11 Displaying an Animated Progress Bar 542
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
Table of Contents | xi
Preface 1
It may be difficult to imagine that a technology born as recently as 1995 would have
had enough of a life cycle to experience a rise and fall in popularity, followed now by
an amazing renaissance. Client-side scripting, begun initially with JavaScript embed-
ded in Netscape Navigator 2, has experienced such a roller coaster ride. A number of
early incompatibilities among major browsers caused many a content author’s head
to ache. But we learned to live with it, as a long period of stability in one platform—
Internet Explorer 6, in particular—meant that we could use our well-worn compati-
bility workarounds without cause for concern. Another stabilizing factor was the
W3C DOM Level 2 specification, which remained a major target for browser makers
not following Microsoft’s proprietary ways. Mozilla, Safari, and Opera used the
W3C DOM as the model to implement, even if Microsoft didn’t seem to be in a
hurry to follow suit in all cases.
Two factors have contributed to the rebirth of interest in JavaScript and Dynamic
HTML. The first is the wide proliferation of broadband connections. Implementing
large client-side applications in JavaScript can take a bunch of code, all of which
must be downloaded to the browser. At dial-up speeds, piling a 50–75 kilobyte script
onto a page could seriously degrade perceived performance; at broadband speeds,
nobody notices the difference.
But without a doubt, the major attraction these days is the now widespread availabil-
ity in all mainstream browsers of a technology first implemented by Microsoft: the
XMLHttpRequest object. It’s a mouthful (leading some to refer to it as, simply, XHR),
but it allows background communication between the browser and server so that a
script can request incremental data from the server and update only a portion of a
page. It is far more efficient than downloading a bunch of data with the page and less
visually disruptive than the old submit-and-wait-for-a-new-page process. To help put
a label on the type of applications one can build with this technology, the term Asyn-
chronous JavaScript and XML (Ajax) was coined. In truth, Ajax is simply a catchy
handle for an existing technology.
xiii
Ajax has opened the floodgates for web developers. Perhaps the most popular first
implementation was Google Maps, whereby you could drag your way around a map,
while scripts and the XMLHttpRequest object in the background downloaded adjacent
blocks of the map in anticipation of your dragging your way over there. It was
smooth, fast, and a real joy to use. And now, more powerful applications—word
processors, spreadsheets, email clients—are being built with JavaScript and
DHTML.
JavaScript in the browser was originally designed for small scripts to work on small
client-side tasks. It is still used that way quite a bit around the Web. Not every appli-
cation is a mega DHTML app. Therefore, this collection of recipes still has plenty of
small tasks in mind. At the same time, however, many recipes from the first edition
have been revised with scripting practices that will serve both the beginner and the
more advanced scripter well. Examples prepare you for the eventuality that your
scripting skills will grow, perhaps leading to a mega DHTML app in the future. Even
so, there are plenty of times when you need an answer to that age-old programming
question: “How do I...?”
About You
Client-side scripting and DHTML are such broad and deep subjects that virtually
every reader coming to this book will have different experience levels, expectations,
and perhaps, fears. No book could hope to anticipate every possible question from
someone wishing to use these technologies in his web pages. Therefore, this book
makes some assumptions about readers at various stages of their experience:
• You have at least rudimentary knowledge of client-side JavaScript concepts. You
know how to put scripts into a web page—where <script> tags go, as well as
how to link an external .js file into the current page. You also know what vari-
ables, strings, numbers, Booleans, arrays, and objects are—even if you don’t
necessarily remember the precise way they’re used with the JavaScript language.
This book is not a tutorial, but you can learn a lot from reading the introduc-
tions to each chapter and the discussions following each solution.
• You may be a casual scripter, who wants to put a bit of intelligence into a web
page for some project or other. You don’t use the language or object model every
day, so you need a refresher about even some simple things, such as the correct
syntax for creating an array or preloading images for fast image rollover effects.
• While surfing the Web, you may have encountered some scripted DHTML effect
that you’d like to implement or adapt for your own pages, but either you can’t
decipher the code you see or you want to “roll your own” version to avoid copy-
right problems with the code’s original owner. If the effect or technique you’ve
seen is fairly popular, this cookbook probably has a recipe for it. You can use these
recipes as they are or modify them to fit your designs. There are no royalties or
xiv | Preface
copyrights to worry about, as long as you don’t offer these recipes to others as
part of a collection of scripts. Of course, if you wish to acknowledge this book in
your source code comments, that would be great!
• You may be an experienced web developer who has probed gingerly, if at all,
into client-side scripting. The horror stories of yore about browser incompatibili-
ties have kept your focus entirely on server-side programming. But now that so
many mainstream sites are using client-side scripting to improve the user experi-
ence, you are ready to take another look at what is out there.
• At the far end of the spectrum, you may be an experienced client-side DHTML
developer in search of new ideas and techniques. For instance, you may have
developed exclusively for the Internet Explorer browser on the Windows plat-
form, but you wish to gravitate toward standards-compatible syntax for future
coding.
Virtually every reader will find that some recipes in this book are too simple and oth-
ers are too complex for their experience level. I hope the more difficult ones chal-
lenge you to learn more and improve your skills. Even if you think you know it all,
be sure to check the discussions of the easier recipes for tips and insights that may be
new to you.
xvi | Preface
script statements. If multiple windows are your nemesis, then Chapter 6, Managing
Browser Windows, provides plenty of ideas to handle communication between win-
dows. A few recipes present suggestions for modal windows (or facsimiles thereof).
Not everyone is a frame lover, but Chapter 7, Managing Multiple Frames, may be of
interest to all, especially if you don’t want your site being “framed” by another site.
Intelligent forms—one of the driving forces behind the creation of client-side script-
ing—are the subject of Chapter 8, Dynamic Forms. Updated to modern techniques,
recipes include form validation (with or without regular expressions) and some cool
but subtle techniques found on some of the most popular web sites on the Internet.
Interactivity with the user is driven by event processing, and Chapter 9, Managing
Events, covers the most common event processing tasks you’ll encounter with
DHTML scripting. Events (and one of the libraries shown in Chapter 9) ripple
through most of the remaining chapters’ recipes. That includes many recipes in
Chapter 10, Page Navigation Techniques, where you’ll see how to implement a vari-
ety of menuing designs and pass data from one page to the next. Chapter 11, Manag-
ing Style Sheets, provides recipes for both basic and advanced style sheet techniques
as they apply to dynamic content, including how to load a browser- or operating sys-
tem-specific stylesheet into the page. Style sheets play a big role in Chapter 12, Visual
Effects for Stationary Content, where recipes abound for image rollovers and user-
controlled font sizes, to name a couple.
Chapter 13, Positioning HTML Elements, addresses numerous challenges in keeping
positioned elements under tight rein. A positioning library recipe is used extensively
throughout the rest of the book, including more recipes in this chapter for animating
elements, scrolling content, and creating a draggable element. In Chapter 14, Creat-
ing Dynamic Content, the W3C DOM and XMLHttpRequest object get good workouts
with recipes for tasks such as embedding JavaScript and XML data within a docu-
ment, transforming data into renderable HTML content, and sorting HTML tables
instantly on the client. Additional dynamic content recipes come in Chapter 15,
Dynamic Content Applications, where more complex recipes show you how to use
DHTML for a slide show, a user-editable document, and a pop-up calendar date
picker, among others.
Browser Platforms
Freed from having to worry much about compatibility with very old browsers, the
goal of each recipe’s design in this edition is to work in the following browsers:
• Microsoft Internet Explorer 6 or later
• Mozilla 1.7.5 (Firefox 1.0, Netscape 8.0, Camino 1.0) or later
• Apple Safari 1.2 or later (including the Windows version)
• Opera 7 or later
xviii | Preface
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in
this book in your programs and documentation. You do not need to contact us for
permission unless you’re reproducing a significant portion of the code. For example,
writing a program that uses several chunks of code from this book does not require
permission. Selling or distributing a CD-ROM of examples from O’Reilly books does
require permission. Answering a question by citing this book and quoting example
code does not require permission. Incorporating a significant amount of example
code from this book into your product’s documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the
title, author, publisher, and ISBN. For example: “JavaScript & DHTML Cookbook,
Second Edition, by Danny Goodman. Copyright 2007 Danny Goodman, 978-0-596-
51408-2.”
If you feel your use of code examples falls outside fair use or the permission given
here, feel free to contact us at [email protected].
Language: English
BY MRS. THOMSON,
AUTHOR OF
“MEMOIRS OF THE COURT OF HENRY THE EIGHTH,”
“LIFE OF SIR WALTER RALEGH,”
“MEMOIRS OF SARAH, DUCHESS OF MARLBOROUGH,”
&c., &c.
IN THREE VOLUMES.
VOL. III.
LONDON:
HURST AND BLACKETT, PUBLISHERS,
SUCCESSORS TO HENRY COLBURN,
13, GREAT MARLBOROUGH STREET.
1860.
CHAPTER I.
CHAPTER II.
CHAPTER III.
Felton--His Character--Uncertainty of his Motives--
Circumstances under which he was brought into Contact
with Buckingham--Motives of his Crime discussed--The
Remonstrance--The Fate of La Rochelle--Buckingham’s
Unpopularity--Returns to Rhé--Misgivings of his Friends--
Interview with Laud--with Charles I.--His Farewell--He
enters Portsmouth--Felton--The Assassination--Original
Letters from Sir D. Carlton and Sir Charles Morgan--The
King’s Grief 89
CHAPTER IV.
CHAPTER V.
CHAPTER VI.
Appendix 321
CHAPTER I.
CHAPTER I.
And again, on the sixteenth of June, was sent another epistle, full
of affection:--
"My dere Lord,--I was very much joy’d at the receiving yr leter last
night, and I will assure you I do not only right cheerfully, but am so
in my hart, and outwardly every on may see it, and so they do, for
they tell me they ar glad to see me so cheerfull, and I hop sences. I
will assure you I will not fayle to keep my promis wth you; I hope
you will not deseve me in breaking yours, for I protest if you should,
it woold half kill me: and I give you humble thanks for saying you
will likewise keepe your word with me in the outher mane bisnes,[34]
as you call it. I am very glad you cam so well to yr jorneys end, but
sorey it was so latt, for Mr. Murey told me it was nine a clocke before
you gott thether. I pray lett me here as often from you as you can,
and send me word when I shall be so hapye as to se you, for I shall
think it very longe, my lord: I thanke God I am very well, so
farwelle, my dere Lord, your true loving, and obedient wife,
"K. Buckingham.[35]
"My Lord, for God sake lett some of that money wch you in tended
to have at Portsmouth to be left wth Dick Oliver, if it be but five
hundred pound to pay Mr. Ward for a ringe and for a cross wh you
gave to my Lady Exeter: for Jesus sake do this, for I am so hanted
with them for it, that I do not know what to do; if you will but send
me 400l. I will dispatch them myself, for I cannot ster for them.[36]
"I beseech you remember my cusin Turpine.
“To the Duke of Buckingham, my dere husband.”[37]
"My deerly beloved sonne--I am very sorrie you have entered into so
great busines, and so little care to supply your wants as you see by
the little hast that is mad to you. I hop your eys wil be oppened to
se what a greate goulfe of businesses you have put your selfe into,
and so little regarded at home, wher all is mery and well plesed,
though the shepes be not vitiled as yet, nor mariners to go with
them: as for monyis the kingdom will not supply your expences, and
every man grones under the burden of the tymes. At your departuer
from me, you tould me you went to make pece, but it was not from
your hart: this is not the way for you to imbroule the hole christian
world in warrs, and then to declare it for religion, and make God a
partie to this wofull affare so far from God as light and darknes; and
the high way to make all christian Princes to bend ther forces
against us, that other ways in policie would have taken our parts.
You knew the worthy King your master[58] never liked that way, and
as far as I can perseve ther is non that crise not out of it. You that
acknowleg the infinite mercy and providence of all mightie god in
preserving your life amongest so many that false doune ded on
every side you, and spares you for more honor to himself, if you
would not be wilfully blind and overthro your selfe, body and soule,
for he hath not I hope made yu so great and gevin you so many
exsellent parts as to suffer you to die in a dich,--let me that is your
mother intreat you to spend some of your ouers in prayers, and
meditating what is fitting and plesing in His sight that has done so
much for you, and that honor you so much strive for: bend it for his
honor and glorie, and you will sone find a chang so great that you
would not for all the kinddomes in world for goe, if you might have
them at your disposing: and do not think it out of fere and
timberousnes of a woman I perswad you to this;--no, no, it is that I
scorne. I would have you leve this bluddy way in which you are
exept into, I am sure contray to your natuer and disposition. God
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.
ebooknice.com