Title: JavaScript: Objects and Object Models
1JavaScriptObjects and Object Models
- October 25, 2005
- Slides modified fromInternet World Wide Web
How to Program. 2004 (3rd) edition. By Deitel,
Deitel, and Goldberg. Published by Prentice Hall.
ISBN 0-13-145091-3
2Chapter 12 - JavaScript Objects
Outline 12.1 Introduction 12.2 Thinking About
Objects 12.3 Math Object 12.4 String
Object 12.4.1 Fundamentals of Characters and
Strings 12.4.2 Methods of the String
Object 12.4.3 Character-Processing
Methods 12.4.4 Searching Methods 12.4.5
Splitting Strings and Obtaining
Substrings 12.4.6 XHTML Markup Methods 12.5
Date Object 12.6 Boolean and Number
Objects 12.7 document Object 12.8 window
Object 12.9 Using Cookies 12.10 Final
JavaScript Example 12.11 Web Resources
312.1 Introduction
- Use JavaScript to manipulate every element of
XHTML document from a script - Reference for several of JavaScripts built-in
objects - Demonstrates the capabilities
412.2 Thinking About Objects
- Objects
- Attributes
- Behaviors
- Encapsulate date and methods
- Property of information hiding
- Details hidden within the objects themselves
5Key Objects in JavaScript
- Key objects
- http//www.w3schools.com/jsref/default.asp
- Exhaustive list
- http//www.devguru.com/Technologies/ecmascript/qui
ckref/js_objects.html - String
- Date
- Math
- Number and Boolean
612.4 String Object
- JavaScripts string and character-processing
capabilities - Appropriate for processing names, addresses,
credit card information, etc. - 12.4.1 Fundamentals of Characters and Strings
- Characters
- Fundamental building blocks of JavaScript
programs - String
- Series of characters treated as a single unit
712.4.2 Methods of the String Object
Fig. 12.3 String object methods.
812.4.2 Methods of the String Object
Fig. 12.3 String object methods.
912.4.2 Methods of the String Object
1012.4.3 Character Processing Methods
- charAt
- Returns the character at specific position
- charCodeAt
- Returns Unicode value of the character at
specific position - fromCharCode
- Returns string created from series of Unicode
values - toLowerCase
- Returns lowercase version of string
- toUpperCase
- Returns uppercase version of string
1112.4.4 Searching Methods
- indexOf and lastIndexOf
- Search for a specified substring in a string
1212.4.5 Splitting Strings and Obtaining Substrings
- Tokenization
- The process of breaking a string into tokens
- Tokens
- Individual words
- Separated by delimiters
- String.split()
- String.substr(start, length) and
String.substring(indexA, indexB)
1312.4.6 XHTML Markup Methods
- Anchor
- lta name topgt Anchor lt/agt
- Blink
- ltblinkgt blinking text lt/blinkgt
- Fixed
- ltttgt monospaced text lt/ttgt
- Strike
- ltstrikegt strike out text lt/strikegt
- Subscript
- ltsubgt subscript lt/subgt
- Superscript
- ltsupgt superscript lt/supgt
1412.5 Date Object
- Provides methods for date and time manipulations
1512.5 Date Object
1612.5 Date Object
1712.5 Date Object
1812.3 Math Object
- Allow the programmer to perform many common
mathematical calculations
1912.3 Math Object
Fig. 12.1 Math object methods.
2012.3 Math Object
2112.3 Math Object
2212.6 Boolean and Number Objects
- Object wrappers for boolean true/false values and
numbers
2312.6 Boolean and Number Objects
2412.6 Boolean and Number Objects
2512.7 document Object
- Manipulate document that is currently visible in
the browser window
2612.7 document Object
2712.8 window Object
- Provides methods for manipulating browser window
28window.html1 of 7
29window.html2 of 7
30window.html3 of 7
31window.html4 of 7
32window.html5 of 7
33window.html6 of 7
34window.html7 of 7
35(No Transcript)
36(No Transcript)
3712.8 window Object
3812.9 Using Cookies
- Cookie
- Data stored on users computer to maintain
information about client during and between
browser sessions - Can be accessed through cookie property
- Set expiration date through expires property
- Use escape function to convert non-alphanumeric
characters to hexadecimal escape sequences - unescape function converts hexadecimal escape
sequences back to English characters - http//www.yourhtmlsource.com/javascript/cookies.h
tml
39cookie.html1 of 4
40cookie.html2 of 4
41cookie.html3 of 4
42cookie.html4 of 4
43Chapter 13 - Dynamic HTML Object Model and
Collections
Outline 13.1 Introduction 13.2 Object
Referencing 13.3 Collections all and children
13.4 Dynamic Styles 13.5 Dynamic
Positioning 13.6 Using the frames Collection
13.7 navigator Object 13.8 Summary of the
DHTML Object Model
44Objectives
- In this lesson, you will learn
- To use the Dynamic HTML Object Model and
scripting to create dynamic Web pages. - To understand the Dynamic HTML object hierarchy.
- To use the all and children collections to
enumerate all of the XHTML elements of a Web
page. - To use dynamic styles and dynamic positioning.
- To use the frames collection to access objects in
a separate frame on your Web page. - To use the navigator object to determine which
browser is being used to access your page.
4513.1 Introduction
- Dynamic HTML Object Model
- Allows Web authors to control the presentation of
their pages - Gives them access to all the elements on their
pages - Web page
- Elements, forms, frames, tables
- Represented in an object hierarchy
- Scripting
- Retrieve and modify properties and attributes
- Referring to text
- http//www.irt.org/script/1370.htm
4613.8 Summary of the DHTML Object Model
Fig. 13.10 DHTML Object Model.
4713.2 Object Referencing
- The simplest way to reference an element is by
using the elements id attribute. - The element is represented as an object
- XHTML attributes become properties that can be
manipulated by scripting
48(No Transcript)
4913.3 Collections all and children
- Collections
- Arrays of related objects on a page
- all
- all the XHTML elements in a document
- children
- Specific element contains that elements child
elements
50Outline
all.html(1 of 2)
51Outline
5213.4 Dynamic Styles
- Elements style can be changed dynamically
- Dynamic HTML Object Model also allows you to
change the class attribute
53Outline
dynamicstyle.html(1 of 2)
54Outline
dynamicstyle2.html(1 of 2)
5513.5 Dynamic Positioning
- XHTML elements can be positioned with scripting
- Declare an elements CSS position property to be
either absolute or relative - Move the element by manipulating any of the top,
left, right or bottom CSS properties
56Outline
5713.6 Using the frames Collection
- Referencing elements and objects in different
frames by using the frames collection
58Outline
59(No Transcript)
6013.7 navigator Object
- Netscape, Mozilla, Microsofts Internet Explorer
- Others as well
- Contains information about the Web browser
- Allows Web authors to determine what browser the
user is using
61Outline
navigator.html(1 of 2)
6213.8 Summary of the DHTML Object Model
Fig. 13.10 DHTML Object Model.
6313.8 Summary of the DHTML Object Model
6413.8 Summary of the DHTML Object Model
6513.8 Summary of the DHTML Object Model
66Helpful references
- http//www.devguru.com/Technologies/ecmascript/qui
ckref/js_objects.html - http//www.w3schools.com/js/js_obj_htmldom.asp