 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 20 – Dynamic HTML: Object Model and Collections Outline 20.1Introduction 20.2Object Referencing.

Slides:



Advertisements
Similar presentations
1 Introduction to Web Application Implement JavaScript in HTML.
Advertisements

Session 10 Dynamic HTML: Cascading Style Sheets™ (CSS), Object Model and Collections Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Pemrograman Teknologi Internet W09: DOM & DHTML. 2 Objectives DOM: DOM: DOM Nodes & Trees DOM Nodes & Trees Traversing & Modifying DOM Trees Traversing.
Working with Special Effects Creating Rollovers, Menus, Filters, and Transitions.
The Web Warrior Guide to Web Design Technologies
Introduction to Cascading Style Sheets (CSS) Module 2: HTML Basics LESSON 4.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Javascript Document Object Model. How to use JavaScript  JavaScript can be embedded into your html pages in a couple of ways  in elements in both and.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Page 1 of 39 Javascript Chapters 13, 14 Vadim Parizher Computer Science Department California State University, Northridge Fall 2003 Slides from text Book.
Dynamic HTML (DHTML) Overview Cascading Style Sheets Document Object Model Event Model Filters and Transitions Data Binding Cross-Browser Compatibility.
JavaScript, Third Edition
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic DHTML.
TECH2018 Multimedia and the Internet More about CSS and Page Layouts.
© 2012 Adobe Systems Incorporated. All Rights Reserved. LEARNING THE LANGUAGE OF THE WEB INTRODUCTION TO HTML AND CSS.
DHTML - Introduction Introduction to DHTML, the DOM, JS review.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
4.1 JavaScript Introduction
Chapter 11 Cascading Style Sheets: Part I The Web Warrior Guide to Web Design Technologies.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
CSS Cascading Style Sheets By Garrett Garman. CSS Why use Style Sheets? Separates Appearance and Structure Modularity Quick and Easy changes Flexibility.
Cascading Style Sheets. Defines the presentation of one or more web pages Similar to a template Can control the appearance of an entire web site giving.
Tutorial 6 By Sam INE 1020 Introduction to Internet Engineering 1 DHTML & CSS Tutorial 6.
Unobtrusive JavaScript
1 JavaScript: Objects and Object Models October 25, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel,
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
CP2022 Multimedia Internet Communication1 HTML and Hypertext The workings of the web Lecture 7.
Creating an Animated Web Page
Working with Objects Creating a Dynamic Web Page.
CITS1231 Web Technologies JavaScript and Document Object Model.
XP Tutorial 4 New Perspectives on JavaScript, Comprehensive1 Working with Objects Creating an Animated Web Page.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 20 – Dynamic HTML: Path, Sequencer and Sprite ActiveX Controls Outline 20.1Introduction 20.2DirectAnimation.
Tutorial 5 Formatting with CSS. Objectives Session 5.1 – Evaluate why CSS styles are used – Determine where to write styles – Create an element selector.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
JavaScript, Fourth Edition
Review of Client Server Model Notes courtesy of Deitel, Deitel and Nieto, (2001) e-Business and e-Commerce: How to Program, PrenticeHall. Dr. Kleist.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 15 – Case Study: Message Forum with Active Server Pages Outline 15.1Introduction 15.2Setup and.
Cascading Style Sheets Class 2, Lecture 2 Rachel A Ober
ALBERT WAVERING BOBBY SENG. Week 2: HTML + CSS  Quiz  Announcements/questions/etc  Some functional HTML elements.
XP Tutorial 12 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Special Effects Creating Rollovers, Menus, Filters, and Transitions.
DHTML - Introduction Chapter Introduction to DHTML, the DOM, JS review.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
DHTML: Working with Objects Creating a Dynamic Web Page.
Chapter 5: Windows and Frames
Chapter 8 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 8 Sebesta: Programming the World Wide Web.
Chapter 7: DHTML: Object Model and Collections CIS 275—Web Application Development for Business I.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
Introduction to the Document Object Model DOM *Understand document structure manipulation *Dynamic effects in web pages *Programming, scripting, web content.
Web Development 101 Presented by John Valance
DHTML. What is it? Dynamic HTML. Not a standard unlike HTML or Java It is a term applied by both Netscape and Microsoft to a collection of technologies.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
CSS1 Dynamic HTML Objects, Collections & Events. CSS2 Introduction Dynamic HTML treats HTML elements as objects. Element’s parameters can be treated as.
Introduction to DHTML. What is DHTML? Dynamic HTML Just as Access is Dynamic Database environment Can have controls that respond to events Can have centralized.
OV Copyright © 2008 Element K Content LLC. All rights reserved.  Format Text  Format Lists  Format Images  Modify Page Background Applying Styles.
CSS Hadas Kahsay. Overview  What is CSS  Basic syntax of CSS Rules  How to link CSS style to html documents  Browsers and CSS  Advantages of CSS.
Lesson 30: JavaScript and DHTML Fundamentals. Objectives Define and contrast client-side and server-side technologies used to create dynamic content for.
JavaScript Object Model. Biggest Advantage of JavaScript  I can access values of HTML elements using JavaScript  I can modify values of HTML elements.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 15 – Dynamic HTML: Object Model and Collections Outline 15.1Introduction 15.2Object Referencing.
1 Lesson 6 Introducing JavaScript HTML and JavaScript BASICS, 4 th Edition.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
JavaScript and Ajax (JavaScript Dynamic HTML (DHTML)) Week 7 Web site:
Blended HTML and CSS Fundamentals 3 rd EDITION Tutorial 3 Introducing Cascading Style Sheets.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Chapter 4 Frames and Cascading Style Sheets. Frames Frames divide a browser window into two or more separate pieces or panes, with each pane containing.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
Chapter 13: DHTML: Object Model and Collections CIS 275—Web Application Development for Business I.
DHTML.
Chapter 13 - Dynamic HTML: Object Model and Collections
Chapter 13 - Dynamic HTML: Object Model and Collections
Presentation transcript:

 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 20 – Dynamic HTML: Object Model and Collections Outline 20.1Introduction 20.2Object Referencing 20.3Collections all and children 20.4Dynamic Styles 20.5Dynamic Positioning 20.6Using the frames Collection 20.7 navigator Object 20.8Summary of the DHTML Object Model

 2001 Deitel & Associates, Inc. All rights reserved Introduction Dynamic HTML object model –Great control over presentation of pages Access to all elements on the page –Whole web page (elements, forms, frames, tables, etc.) represented in an object hierarchy HTML elements treated as objects –Attributes of these elements treated as properties of those objects Objects identified with an ID attribute can be scripted with languages like JavaScript, JScript and VBScript

 2001 Deitel & Associates, Inc. All rights reserved Object Referencing Simplest way to reference an element is by its ID attribute Changing the text displayed on screen –Example of a Dynamic HTML ability called dynamic content

 2001 Deitel & Associates, Inc. All rights reserved. Outline 1.1 innerText property Object pText refers to the P element whose ID is set to pText (line 22) innertext property refers to text contained in element Object Model function start() 12 { 13 alert( pText.innerText ); 14 pText.innerText = "Thanks for coming."; 15 } Welcome to our Web page!

 2001 Deitel & Associates, Inc. All rights reserved. 5 Object referencing with the Dynamic HTML Object Model

 2001 Deitel & Associates, Inc. All rights reserved Collections all and children Collections are basically arrays of related objects on a page all –Collection of all the HTML elements in a document in the order in which they appear length property –Specifies the number of elements in the collection tagName property of an element –Determines the name of the element Every element has its own all collection, consisting of all the elements contained within that element

 2001 Deitel & Associates, Inc. All rights reserved. Outline 1.Document’s all collection 1.1Loop through the collection and list the element names 2. and tags both have ! as their tagName Object Model var elements = ""; function start() 14 { 15 for ( var loop = 0; loop < document.all.length; ++loop ) 16 elements += " " + document.all[ loop ].tagName; pText.innerHTML += elements; 19 } Elements on this Web page:

 2001 Deitel & Associates, Inc. All rights reserved. 8 Looping through the all collection

 2001 Deitel & Associates, Inc. All rights reserved Collections all and children The children collection –Contains only those elements that are direct child elements of that element –An HTML element has only two children: the HEAD element and the BODY element

 2001 Deitel & Associates, Inc. All rights reserved. Outline 1.Document’s children collection 1.1Loop recursively through the children collections Object Model var elements = " "; function child( object ) 14 { 15 var loop = 0; elements += " " + object.tagName + " "; for ( loop = 0; loop < object.children.length; loop++ ) { if ( object.children[loop].children.length ) 22 child( object.children[ loop ] ); 23 else 24 elements += " " + object.children[ loop ].tagName 25 + " "; 26 } elements += " "; 29 } 30

 2001 Deitel & Associates, Inc. All rights reserved. Outline 2. outerHTML property includes enclosing HTML tags as well as the content inside <BODY ONLOAD = "child( document.all[ 1 ] ); 34 myDisplay.outerHTML += elements;"> Welcome to our Web page! Elements on this Web page:

 2001 Deitel & Associates, Inc. All rights reserved. 12 Navigating the object hierarchy using collection children

 2001 Deitel & Associates, Inc. All rights reserved Dynamic Styles Refer to the background color of a page as document.body.style.backgroundColor Dynamic HTML object model allows you to change the CLASS attribute of an element

 2001 Deitel & Associates, Inc. All rights reserved. Outline 1.1Function start prompt ’s the user to enter a color name, then sets the background color to that value Object Model function start() 12 { 13 var inputColor = prompt( "Enter a color name for the " + 14 "background of this page", "" ); 15 document.body.style.backgroundColor = inputColor; 16 } Welcome to our Web site!

 2001 Deitel & Associates, Inc. All rights reserved. 15 Dynamic styles

 2001 Deitel & Associates, Inc. All rights reserved. Outline 1.1Define style classes 1.2Function start prompt ’s the user for a class name and dynamically changes the font to reflect the user’s choice Object Model bigText { font-size: 3em; 13 font-weight: bold } smallText { font-size:.75em } function start() 21 { 22 var inputClass = prompt( "Enter a className for the text " 23 + "(bigText or smallText)", "" ); 24 pText.className = inputClass; 25 } Welcome to our Web site!

 2001 Deitel & Associates, Inc. All rights reserved. 17 Dynamic styles in action

 2001 Deitel & Associates, Inc. All rights reserved Dynamic Positioning Dynamic positioning –An element can be positioned with scripting setInterval function takes two parameters: –A function name –How often to run that function –clearInterval function stops the timer setTimeout function similar, but only calls the function once –clearTimeout function stops the timer

 2001 Deitel & Associates, Inc. All rights reserved. Outline 1.1 setInterval function 1.2 color, fontFamily and fontSize attributes Dynamic Positioning var speed = 5; 12 var count = 10; 13 var direction = 1; 14 var firstLine = "Text growing"; 15 var fontStyle = [ "serif", "sans-serif", "monospace" ]; 16 var fontStylecount = 0; function start() 19 { 20 window.setInterval( "run()", 100 ); 21 } function run() 24 { 25 count += speed; if ( ( count % 200 ) == 0 ) { 28 speed *= -1; 29 direction = !direction; 30

 2001 Deitel & Associates, Inc. All rights reserved. Outline 31 pText.style.color = 32 ( speed < 0 ) ? "red" : "blue" ; 33 firstLine = 34 ( speed < 0 ) ? "Text shrinking" : "Text growing"; 35 pText.style.fontFamily = 36 fontStyle[ ++fontStylecount % 3 ]; 37 } pText.style.fontSize = count / 3; 40 pText.style.left = count; 41 pText.innerHTML = firstLine + " Font size: " + 42 count + "px"; 43 } <P ID = "pText" STYLE = "position: absolute; left: 0; 50 font-family: serif; color: blue"> 51Welcome!

 2001 Deitel & Associates, Inc. All rights reserved. 21 Dynamic positioning

 2001 Deitel & Associates, Inc. All rights reserved Using the frames Collection frames collection –To reference a frame, use frames(“name”) where name is the ID or NAME of the desired frame Ex. frames(“lower”) refers to the element in the frames collection with an ID or NAME of lower

 2001 Deitel & Associates, Inc. All rights reserved. Outline 1.FRAMESET file for cross-frame scripting Frames collection

 2001 Deitel & Associates, Inc. All rights reserved. Outline 2.Access other frames using frames collection The frames collection function start() 28 { 29 var text = prompt( "What is your name?", "" ); 30 parent.frames( "lower" ).document.write( " Hello, " + 31 text + " " ); 32 } Cross-frame scripting!

 2001 Deitel & Associates, Inc. All rights reserved. 25 Accessing other frames

 2001 Deitel & Associates, Inc. All rights reserved Navigator Object navigator object –Supported by Netscape Navigator and Internet Explorer –navigator object contains info about the Web browser viewing the page –navigator.appName contains the name of the application “ Microsoft Internet Explorer ” “ Netscape ” –Value of navigator.appVersion not a simple integer Contains other info, such as OS When using a browser-specific technology –Make provisions for other browsers

 2001 Deitel & Associates, Inc. All rights reserved. Outline 1.Using the navigator object to redirect to appropriate pages The navigator Object function start() 12 { 13 if ( navigator.appName == "Microsoft Internet Explorer" ) { if ( navigator.appVersion.substring( 1, 0 ) >= "4" ) 16 document.location = "newIEversion.html"; 17 else 18 document.location = "oldIEversion.html"; 19 } 20 else 21 document.location = "NSversion.html"; 22 } Redirecting your browser to the appropriate page, 29please wait

 2001 Deitel & Associates, Inc. All rights reserved Summary of the DHTML Object Model DHTML object model –Allows script programmer to access every element in an HTML document –Every element a separate object

 2001 Deitel & Associates, Inc. All rights reserved Summary of the DHTML Object Model window document history navigator applets all anchors body embeds forms filters images links plugins styleSheets scripts location screen event document plugins object collection Key frames

 2001 Deitel & Associates, Inc. All rights reserved Summary of the DHTML Object Model Objects in the Internet Explorer 5 object model

 2001 Deitel & Associates, Inc. All rights reserved Summary of the DHTML Object Model Objects in the Internet Explorer 5 object model –Continued from previous slide

 2001 Deitel & Associates, Inc. All rights reserved Summary of the DHTML Object Model Collections in the Internet Explorer 5 object model

 2001 Deitel & Associates, Inc. All rights reserved Summary of the DHTML Object Model Collections in the Internet Explorer 5 object Model –Continued from the previous slide