JavaScript & DHTML Cookbool(

Similar documents
THIRD EDITION. CSS Cookbook. Christopher Schmitt foreword by Dan Cederholm O'REILLY 8. Beijing Cambridge Farnham Koln Sebastopol Taipei Tokyo

jquery Cookbook jquery Community Experts O'REILLY8 Tokyo Taipei Sebastopol Beijing Cambridge Farnham Koln

Chapter 1 Introduction to Dreamweaver CS3 1. About Dreamweaver CS3 Interface...4. Creating New Webpages...10

Creating Web Pages with HTML-Level III Tutorials HTML 6.01

This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

PHP / MYSQL DURATION: 2 MONTHS

CSS THE M\SS1NG MANUAL. David Sawyer McFarland. POGUE PRESS" O'REILLr Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo

JavaScript: The Definitive Guide

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

ADDING FUNCTIONS TO WEBSITE

the missing manual0 O'REILLY Third Edition David Sawyer McFarland Beijing Cambridge The book that should have been in the box Farnham

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

ver Wfl Adobe lif Sams Teach Yourself Betsy Bruce Robyn Ness SAMS 800 East 96th Street, Indianapolis, Indiana, USA WlM John Ray ^lg^

World Wide Web PROGRAMMING THE PEARSON EIGHTH EDITION. University of Colorado at Colorado Springs

JavaScript Specialist v2.0 Exam 1D0-735

Introduction. Part I: jquery API 1. Chapter 1: Introduction to jquery 3

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8

of numbers, converting into strings, of objects creating, sorting, scrolling images using, sorting, elements of object

SkyVisualEditor Salesforce1 Support Guide

CERTIFICATE IN WEB PROGRAMMING

COPYRIGHTED MATERIAL. Contents. Chapter 1: Creating Structured Documents 1

NEW WEBMASTER HTML & CSS FOR BEGINNERS COURSE SYNOPSIS

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

E ECMAScript, 21 elements collection, HTML, 30 31, 31. Index 161

Web Site Development with HTML/JavaScrip

Enterprise Web Development

Technical Working Paper

JAVASCRIPT FOR PROGRAMMERS

Table Basics. The structure of an table

Mobile MOUSe WEB SITE DESIGN ONLINE COURSE OUTLINE

Sections and Articles

Keynote 08 Basics Website:

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

Exam : 9A Title : Adobe GoLive CS2 ACE Exam. Version : DEMO

Survey Manager - Reference Manual

STRANDS AND STANDARDS

Overview of the Adobe Dreamweaver CS5 workspace

Forms iq Designer Training

Table of Contents. Preface... iii COMPUTER BASICS WINDOWS XP

Independence Community College Independence, Kansas

Table of Contents. Preface... xiii

IMY 110 Theme 11 HTML Frames

Accessibility of EPiServer s Sample Templates

WCAG 2.0 A and AA Requirements

SPARK. User Manual Ver ITLAQ Technologies

Create Web Charts. With jqplot. Apress. Fabio Nelli

Advanced Dreamweaver CS6

App Inventor 2 Create Your Own Android Apps

U N I V E R S I T Y O F K E N T U C K Y. efacts 2-click Interactive Building Information Map ~ Help Guide ~ Revised January 20, 2016

PHP & My SQL Duration-4-6 Months

Deccansoft Software Services

Adobe Dreamweaver CS6 Digital Classroom

Shankersinh Vaghela Bapu Institue of Technology

Developing Web Applications

The figure below shows the Dreamweaver Interface.

Nintex Forms 2010 Help

Design patterns and Animation with jquery. with Paul Bakaus

Varargs Training & Software Development Centre Private Limited, Module: HTML5, CSS3 & JavaScript

SRE VIDYASAAGAR HIGHER SECONDARY SCHOOL. TWO MARKS

EVALUATION ONLY. Table of Contents. iv Labyrinth Learning

How to lay out a web page with CSS

Web Development IB PRECISION EXAMS

Introduction to Dreamweaver CS4:

Coding Faster: Getting More Productive with Microsoft Visual

ABOUT WEB TECHNOLOGY COURSE SCOPE:

Dreamweaver Basics. Planning your website Organize site structure Plan site design & navigation Gather your assets

CS7026 CSS3. CSS3 Graphics Effects

HTML5 in Action ROB CROWTHER JOE LENNON ASH BLUE GREG WANISH MANNING SHELTER ISLAND

Web Viewer Guide. HiPER LOOK Version Copyright 2016 PIXIA Corp. All Rights Reserved.

Learning Perl Objects, References, and Modules

HTML5 MOCK TEST HTML5 MOCK TEST I

Learning Flash CS4 Professional

COMSC-031 Web Site Development- Part 2. Part-Time Instructor: Joenil Mistal

Chapter 1 Getting Started with HTML 5 1. Chapter 2 Introduction to New Elements in HTML 5 21

HTML Syllabus Instructor: TBD

Practical C++ Programming

READSPEAKER ENTERPRISE HIGHLIGHTING 2.5

Skyway Builder Web Control Guide

Basics of Web Technologies

Comcast Store Campaign Planning 2.0 Phase 1 & 2 - Quick Start Guide. Last Updated: 7/5/16

Road Map for Essential Studio 2011 Volume 4

The Scope of This Book... xxii A Quick Note About Browsers and Platforms... xxii The Appendices and Further Resources...xxiii

SOFTRONIICS Call:

Version Control with Git

HTML p. 1 Introduction to HTML p. 1 Getting Started p. 1 The Structure of an HTML Page p. 1 HTML Basics p. 3 The Weather Forecast Page p.

Mobile Site Development

How to Edit Your Website

Figure 1 Forms category in the Insert panel. You set up a form by inserting it and configuring options through the Properties panel.

How to Edit Your Website

Programming the World Wide Web by Robert W. Sebesta

2 Webpage Markup with HTML HTML5 Page Structure Creating a Webpage HTML5 Elements and Entities

AIM. 10 September

With Dreamweaver CS4, Adobe has radically

Arduino Cookbook O'REILLY* Michael Margolis. Tokyo. Cambridge. Beijing. Farnham Koln Sebastopol

Table of Contents. Preface...iii. INTRODUCTION 1. Introduction to M ultimedia and Web Design 1. ILLUSTRATOR CS6 1. Introducing Illustrator CS6 17

,

JSN EasySlider Configuration Manual

COPYRIGHTED MATERIAL. Contents. Introduction. Chapter 1: Structuring Documents for the Web 1

PVII Pop Menu Magic 3


Transcription:

SECOND EDITION JavaScript & DHTML Cookbool( Danny Goodman O'REILLY Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo

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 2. Numbers and Dates 27 2.1 Converting Between Numbers and Strings 31 2.2 Testing a Number's Validity 33 2.3 Testing Numeric Equality 34 2.4 Rounding Floating-Point Numbers 35 2.5 Formatting Numbers for Text Display 36 2.6 Converting Between Decimal and Hexadecimal Numbers 39 2.7 Generating Pseudorandom Numbers 41 2.8 Calculating Trigonometric Functions 41 2.9 Creating a Date Object 42

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 3. Arrays and Objects 51 3.1 Creating a Simple Array 54 3.2 Creating a Multidimensional Array 56 3.3 Converting Between Arrays and Strings 57 3.4 Doing Something with the Items in an Array 59 3.5 Sorting a Simple Array 61 3.6 Combining Arrays 63 3.7 Dividing Arrays 64 3.8 Creating a Custom Object 65 3.9 Simulating a Hash Table for Fast Array Lookup 69 3.10 Doing Something with a Property of an Object 71 3.11 Sorting an Array of Objects 72 3.12 Customizing an Object's Prototype 74 3.13 Converting Arrays and Custom Objects to Strings 79 3.14 Using Objects to Reduce Naming Conflicts 82 4. Variables, Functions, and Flow Control 85 4.1 Creating a JavaScript Variable 85 4.2 Creating a Named Function 89 4.3 Nesting Named Functions 92 4.4 Creating an Anonymous Function 93 4.5 Delaying a Function Call 94 4.6 Branching Execution Based an Conditions 97 4.7 Handling Script Errors Gracefully 101 4.8 Improving Script Performance 103 5. Browser Feature Detection 107 5.1 Detecting the Browser Brand 113 5.2 Detecting an Early Browser Version 113 5.3 Detecting the Internet Explorer Version 115 5.4 Detecting the Mozilla Version 116 5.5 Detecting the Safari Version 118 5.6 Detecting the Opera Version 119 5.7 Detecting the Client Operating System 120 5.8 Detecting Object Support 121 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 an Multiple Browser Versions 130 6. Managing Browser Windows 132 6.1 Living with Browser Window Control Limitations 135 6.2 Setting the Main Window's Size 136 6.3 Positioning the Main Window 137 6.4 Maximizing the Main Window 138 6.5 Creating a New Window 139 6.6 Bringing a Window to the Front 143 6.7 Communicating with a New Window 144 6.8 Communicating Back to the Main Window 147 6.9 Using Internet Explorer Modal/Modeless Windows 148 6.10 Simulating a Cross-Browser Modal Dialog Window 151 6.11 Simulating a Window with Layers 158 7. Managing Multiple Frames 173 7.1 Creating a Blank Frame in a New Frameset 178 7.2 Changing the Content of One Frame from Another 179 7.3 Changing the Content of Multiple Frames at Once 181 7.4 Replacing a Frameset with a Single Page 182 7.5 Avoiding Being "Framed" by Another Site 183 7.6 Ensuring a Page Loads in Its Frameset 184 7.7 Reading a Frame's Dimensions 187 7.8 Resizing Frames 188 7.9 Setting Frameset Specifications Dynamically 192 8. Dynamic Forms 194 8.1 Auto-Focusing the First Text Field 197 8.2 Performing Common Text Field Validations 198 8.3 Preventing Form Submission upon Validation Failure 204 8.4 Auto-Focusing an Invalid Text Field Entry 207 8.5 Using a Custom Validation Object 208 8.6 Changing a Form's Action 213 8.7 Blocking Submissions from the Enter Key 214 Talge of Contents I vii

8.8 Advancing Text Field Focus with the Enter Key 215 8.9 Submitting a Form by an Enter Key Press in Any Text Box 216 8.10 Disabling Form Controls 217 8.11 Hiding and Showing Form Controls 219 8.12 Allowing Only Numbers (or Letters) in a Text Box 221 8.13 Auto-Tabbing for Fixed-Length Text Boxes 223 8.14 Changing select Element Content 224 8.15 Copying Form Data Between Pages 227 9. Managing Events 231 9.1 Equalizing the IE and W3C Event Models 236 9.2 Initiating a Process After the Page Loads 240 9.3 Appending Multiple Load Event Handlers 242 9.4 Determining the Coordinates of a Click Event 244 9.5 Preventing an Event from Performing Its Default Behavior 248 9.6 Blocking Duplicate Clicks 251 9.7 Determining Which Element Received an Event 252 9.8 Determining Which Mouse Button Was Pressed 254 9.9 Reading Which Character Key Was Typed 256 9.10 Reading Which Noncharacter Key Was Pressed 257 9.11 Determining Which Modifier Keys Were Pressed During an Event 260 9.12 Determining the Element the Cursor Rolled From/To 262 9.13 Synchronizing Sounds to Events 266 10. Page Navigation Techniques 268 10.1 Loading a New Page or Anchor 271 10.2 Keeping a Page Out of the Browser History 273 10.3 Using a select Element for Navigation 274 10.4 Passing Data Between Pages via Cookies 276 10.5 Passing Data Between Pages via Frames 278 10.6 Passing Data Between Pages via URLs 280 10.7 Creating a Contextual (Right-Click) Menu 283 10.8 Creating Drop-Down Navigation Menus 291 10.9 Providing Navigation Trail Menus 305 10.10 Creating Expandable Menus 308 10.11 Creating Collapsible XML Menus 320 viii I Table of Contents

11. Managing Style Sheets 331 11.1 Assigning Style Sheet Rules to an Element Globally 333 11.2 Assigning Style Sheet Rules to a Subgroup of Elements 334 11.3 Assigning Style Sheet Rules to an Individual Element 336 11.4 Importing External Style Sheets 337 11.5 Importing Browser- or Operating System-Specific Style Sheets 338 11.6 Changing Imported Style Sheets After Loading 340 11.7 Enabling/Disabling Style Sheets 341 11.8 Toggling Between Style Sheets for an Element 342 11.9 Overriding a Style Sheet Rule 343 11.10 Turning Arbitrary Content into a Styled Element 344 11.11 Creating Center-Aligned Body Elements 345 11.12 Reading Effective Style Sheet Property Values 346 11.13 Forcing Recent Browsers into Standards-Compatibility Mode 348 12. Visual Effects for Stationary Content 351 12.1 Precaching Images 354 12.2 Swapping Images (Rollovers) 356 12.3 Reducing Rollover Image Downloads with JavaScript 358 12.4 Reducing Rollover Image Downloads with CSS 362 12.5 Dynamically Changing Image Sizes 366 12.6 Changing Text Style Properties 367 12.7 Offering Body Text Size Choices to Users 370 12.8 Creating Custom Link Styles 374 12.9 Changing Page Background Colors and Images 375 12.10 Hiding and Showing Elements 378 12.11 Adjusting Element Transparency 379 12.12 Creating Transition Visual Effects 381 12.13 Drawing Charts in the Canvas Element 385 13. Positioning HTML Elements 392 13.1 Making an Element Positionable in the Document Space 397 13.2 Connecting a Positioned Element to a Body Element 398 13.3 Controlling Positioning via a DHTML JavaScript Library 400 13.4 Deciding Between div and span Containers 407 13.5 Adjusting Positioned Element Stacking Order (Z-order) 409 13.6 Centering an Element an Top of Another Element 410 13.7 Centering an Element in a Window or Frame 412 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 14. Creating Dynamic Content 452 14.1 Writing Dynamic Content During Page Loading 453 14.2 Creating New Page Content Dynamically 454 14.3 Including External HTML Content 456 14.4 Embedding XML Data 458 14.5 Embedding Data As JavaScript Objects 460 14.6 Transforming XML Data into HTML Tables 463 14.7 Transforming JavaScript Objects into HTML Tables 466 14.8 Converting an XML Node Tree to JavaScript Objects 469 14.9 Creating a New HTML Element 470 14.10 Creating Text Content for a New Element 473 14.11 Creating Mixed Element and Text Nodes 474 14.12 Inserting and Populating an iframe Element 476 14.13 Getting a Reference to an HTML Element Object 478 14.14 Referencing All Elements of the Same Class 480 14.15 Replacing Portions of Body Content 482 14.16 Removing Body Content 483 14.17 Using XMLHttpRequest for a REST Request 485 14.18 Using XMLHttpRequest for a SOAP Call 488 14.19 Sorting Dynamic Tables 491 14.20 Walking the Document Node Tree 494 14.21 Capturing Document Content 498 15. Dynamic Content Applications 500 15.1 Displaying a Random Aphorism 501 15.2 Converting a User Selection into an Arbitrary Element 504 15.3 Automating the Search-and-Replace of Body Content 506 15.4 Designing a User-Editable Content Page 512 15.5 Creating a Slide Show 515 15.6 Auto-Scrolling the Page 523 15.7 Greeting Users with Their Time of Day 524 x I 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 A. Keyboard Event Character Values 548 B. Keyboard Key Code Values 550 C. ECMAScript Reserved Keywords 552 Index 553 fable of Contents I xi