+ All Categories
Home > Documents > DHTML: Working with Objects Creating a Dynamic Web Page.

DHTML: Working with Objects Creating a Dynamic Web Page.

Date post: 13-Jan-2016
Category:
Upload: archibald-armstrong
View: 216 times
Download: 0 times
Share this document with a friend
26
DHTML: Working with Objects Creating a Dynamic Web Page
Transcript
Page 1: DHTML: Working with Objects Creating a Dynamic Web Page.

DHTML:Working with Objects

Creating a Dynamic Web Page

Page 2: DHTML: Working with Objects Creating a Dynamic Web Page.

Introduction to DHTML

• Developers began to look for ways to create dynamic pages

• New approach, in which the HTML code itself supported dynamic elements

• Known collectively as dynamic HTML, or DHTML

Page 3: DHTML: Working with Objects Creating a Dynamic Web Page.

Introduction to DHTML

• Interaction of three aspects– A page’s HTML/XHTML code– A style sheet that defines the styles used in the

page– A script to control the behavior of elements on the

page

Page 4: DHTML: Working with Objects Creating a Dynamic Web Page.

Introduction to DHTML

• Some uses– Animated text– Pop-up menus– Rollovers– Web pages that retrieve their content from

external data sources– Elements that can be dragged and dropped

Page 5: DHTML: Working with Objects Creating a Dynamic Web Page.

Understanding JavaScript Objects

• JavaScript is an object-based language• An object is any item associated with a Web

page or Web browser• Each object has

– Properties– Methods

Page 6: DHTML: Working with Objects Creating a Dynamic Web Page.

Exploring the Document Object Model

• The organized structure of objects and events is called the document object model, or DOM

• Every object related to documents or to browsers should be part of the document object model

• In practice, browsers differ in the objects that their document object models support

Page 7: DHTML: Working with Objects Creating a Dynamic Web Page.

Exploring the Document Object Model

• Development of a Common DOM– Basic model, or DOM Level 0– Supported browser window, Web document, and

the browser itself– Development followed two paths: one adopted by

Netscape and the other adopted by Internet Explorer

– Internet Explorer DOM also provided for capturing events

Page 8: DHTML: Working with Objects Creating a Dynamic Web Page.

Exploring the Document Object Model

• Development of a Common DOM– World Wide Web Consortium (W3C) stepped in to

develop specifications for a common document object model

• DOM Level 1• DOM Level 2• DOM Level 3

Page 9: DHTML: Working with Objects Creating a Dynamic Web Page.

Exploring the Document Object Model

• Development of a Common DOM– Within each DOM, particular features may not be

supported by every browser– Code should be compatible with

• Netscape 4• Internet Explorer 5• W3C DOM Level 1 and 2

Page 10: DHTML: Working with Objects Creating a Dynamic Web Page.

Exploring the Document Object Model

• The document tree

Page 11: DHTML: Working with Objects Creating a Dynamic Web Page.

Referencing Objects

• A DOM can be used by any scripting language including JavaScript and Java

Page 12: DHTML: Working with Objects Creating a Dynamic Web Page.

Referencing Objects

• Object Names– Each object is identified by an object name

Page 13: DHTML: Working with Objects Creating a Dynamic Web Page.

Referencing Objects

• Object Names– General form is object1.object2.object3…– To reference the history you would use the form

window.history– For the body, you would use

document.body

Page 14: DHTML: Working with Objects Creating a Dynamic Web Page.

Referencing Objects

• Working with Object Collections– Objects are organized into arrays called object

collectionsdocument.collection

Page 15: DHTML: Working with Objects Creating a Dynamic Web Page.

Referencing Objects

• Working with Object Collections

Page 16: DHTML: Working with Objects Creating a Dynamic Web Page.

Referencing Objects

• Using document.all and document.getElementById– Not all elements are associated with an object

collection– Can reference these objects using their id values

document.all[“id”]

document.all.id

document.getElementById(“id”)

Page 17: DHTML: Working with Objects Creating a Dynamic Web Page.

Referencing Objects

• Referencing Tags– Internet Explorer DOM

document.all.tags(tag)

document.all.tags(tag)

– W3C DOMsdocument.getElementsbyTagName(“tag”)

document.getElementsbyTagName(“p”)[0]

Page 18: DHTML: Working with Objects Creating a Dynamic Web Page.

Working with Object Properties

• The syntax for setting the value of an object property isobject.property = expression

• Exampledocument.title = “XHTML update”

Page 19: DHTML: Working with Objects Creating a Dynamic Web Page.

Working with Object Properties

Page 20: DHTML: Working with Objects Creating a Dynamic Web Page.

Working with Object Properties

• Some properties are read-only

Page 21: DHTML: Working with Objects Creating a Dynamic Web Page.

Creating a Cross-Browser Web Site

• You can create this kind of code, known as cross-browser code, using two different approaches: browser detection or object detection

Page 22: DHTML: Working with Objects Creating a Dynamic Web Page.

Creating a Cross-Browser Web Site

• Using Browser Detection– Using browser detection, your code determines

which browser (and browser version) a user is runningnavigator.appName

– Most browser detection scripts – commonly known as browser sniffers – use this property to extract information about the version numbernavigator.uerAgent

Page 23: DHTML: Working with Objects Creating a Dynamic Web Page.

Creating a Cross-Browser Web Site

• Using Object Detection– With object detection, you determine which

document object model a browser supports

var NS4DOM = document.layers ? true:false;

var IEDOM = document.all ? true:false;

var W3CDOM = document.getElementByID ? true:false;

Page 24: DHTML: Working with Objects Creating a Dynamic Web Page.

Creating a Cross-Browser Web Site

• Employing Cross-Browser Strategies– One strategy, called page branching, creates

separate pages for each browser along with an initial page

– A script determines the capabilities of the user’s browser and automatically loads the appropriate page

Page 25: DHTML: Working with Objects Creating a Dynamic Web Page.

Creating a Cross-Browser Web Site

• Employing Cross-Browser Strategies

Page 26: DHTML: Working with Objects Creating a Dynamic Web Page.

Working with the style Object

• The syntax for applying a style isobject.style.attribute = value


Recommended