 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.

Slides:



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

 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Pemrograman Teknologi Internet W09: DOM & DHTML. 2 Objectives DOM: DOM: DOM Nodes & Trees DOM Nodes & Trees Traversing & Modifying DOM Trees Traversing.
The Web Warrior Guide to Web Design Technologies
Page 1 of 39 Javascript Chapters 13, 14 Vadim Parizher Computer Science Department California State University, Northridge Fall 2003 Slides from text Book.
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.
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.
 2002 Prentice Hall. All rights reserved. JavaServer Pages.
4.1 JavaScript Introduction
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
 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.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
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.
CSS in XHTML continued Please use speaker notes for additional information!
1 JavaScript: Objects and Object Models October 25, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel,
Chapter 1 XHTML: Part I The Web Warrior Guide to Web Design Technologies.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
Creating an Animated Web Page
Working with Objects Creating a Dynamic Web Page.
CITS1231 Web Technologies JavaScript and Document Object Model.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Tutorial 5 Formatting with CSS. Objectives Session 5.1 – Evaluate why CSS styles are used – Determine where to write styles – Create an element selector.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 34 - Case Study: Active Server Pages and XML Outline 34.1 Introduction 34.2 Setup and Message.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 10 - JavaScript: Functions Outline 10.1 Introduction 10.2 Program Modules in JavaScript 10.3.
JavaScript – The DOM JavaScript is object based The browser is object based – We can access the browser's objects in the same way we did JavaScript's Two.
JavaScript, Fourth Edition
 2001 Prentice Hall, Inc. All rights reserved. Chapter 15 – Case Study: Message Forum with Active Server Pages Outline 15.1Introduction 15.2Setup and.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 20 – Dynamic HTML: Object Model and Collections Outline 20.1Introduction 20.2Object Referencing.
DHTML: Working with Objects Creating a Dynamic Web Page.
Frames in XHTML Please use speaker notes for additional information!
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.
1 Introduction to XHTML: Part 1 Outline Introduction Elements and Attributes Editing XHTML Common Elements W3C XHTML Validation Service Headers Linking.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
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.
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.
INTRODUCTORY Tutorial 5 Using CSS for Layout and Printing.
OV Copyright © 2008 Element K Content LLC. All rights reserved.  Format Text  Format Lists  Format Images  Modify Page Background Applying Styles.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 17 - Dynamic HTML: Structured Graphics ActiveX Control Outline 17.1 Introduction 17.2 Shape Primitives.
CIS 375—Web App Dev II JavaScript I. 2 Introduction to DTD JavaScript is a scripting language developed by ________. A scripting language is a lightweight.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing a Line of Text in a Web Page 7.3 Another JavaScript.
JavaScript Object Model. Biggest Advantage of JavaScript  I can access values of HTML elements using JavaScript  I can modify values of HTML elements.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 15 – Dynamic HTML: Object Model and Collections Outline 15.1Introduction 15.2Object Referencing.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 16 - Dynamic HTML: Data Binding with Tabular Data Control Outline 16.1 Introduction 16.2 Simple.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - JavaScript: Control Structures II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled.
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.
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.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 18 - Dynamic HTML: Path Sequencer and Sprite ActiveX Controls Outline 18.1 Introduction 18.2.
DHTML.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Chapter 13 - Dynamic HTML: Object Model and Collections
Chapter 13 - Dynamic HTML: Object Model and Collections
Working with Dynamic Content and Styles
COP 3813 Intro to Internet Computing
Presentation transcript:

 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 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

 2001 Prentice Hall, Inc. All rights reserved. Outline 2 Reference.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Object Model <!-- 14 function start() 15 { 16 alert( pText.innerText ); 17 pText.innerText = "Thanks for coming."; 18 } 19 // --> Welcome to our Web page! The innerText property of the object refers to the text contained in that element ( Welcome to our Web page! ). Function start displays an alert box containing the value of pText.innerText The onload event calls the JavaScript start function when document loading completes. The innerText property of the object is dynamically changed (Thanks for coming.).

 2001 Prentice Hall, Inc. All rights reserved. Outline 3 Program Output The value of pText.innerText after the function start is invoked. The value of pText.innerText when the page is first loaded. An alert box displaying the value of pText.innerText.

 2001 Prentice Hall, Inc. All rights reserved. Outline 4 All.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Object Model <!-- 14 var elements = ""; function start() 17 { 18 for ( var loop = 0; loop < document.all.length; ++loop ) 19 elements += " " + document.all[ loop ].tagName; pText.innerHTML += elements; 22 alert( elements ); 23 } 24 // --> Elements on this Web page: The for loop loops through the elements of the all collection and display each element’s name. The length property of the all collection specifies the number of elements in the collection. The name of each XHTML element (given in the tagName property) in the collection is appended to elements. The innerHTML property is similar to the innerText property but can also include XHTML formatting. The all collection is a collection of all the XHTML elements in the page in the order they appear.

 2001 Prentice Hall, Inc. All rights reserved. Outline 5 Program Output An alert dialog is displayed with all the names of the XHTML elements in the all collection. The XHTML elements are rendered on the page. Note comments are represented as !.

 2001 Prentice Hall, Inc. All rights reserved. Outline 6 Children.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Object Model <!-- 14 var elements = " "; function child( object ) 17 { 18 var loop = 0; elements += " " + object.tagName + " "; for ( loop = 0; loop < object.children.length; loop++ ) 23 { 24 if ( object.children[ loop ].children.length ) 25 child( object.children[ loop ] ); 26 else 27 elements += " " + 28 object.children[ loop ].tagName + 29 " "; 30 } elements += " "; 33 } 34 // --> Function child uses recursion to view all elements on a page. The script adds ul and li tags to display the elements on the page in a hierarchical manner. If an element has children function child recurses on itself with the child to print these elements out. The children collection for a specific element contains that element’s child elements.

 2001 Prentice Hall, Inc. All rights reserved. Outline 7 Children.html Program Output <body onload = "child( document.all[ 4 ] ); 39 myDisplay.outerHTML += elements;"> Welcome to our Web page! Elements on this Web page: Property outerHTML is similar to property innerHTML but it includes the enclosing XHTML tags (tags and in this case) as well as the content inside them. A display of all the elements in a document.

 2001 Prentice Hall, Inc. All rights reserved. Outline 8 Dynamicstyle.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Object Model <!-- 14 function start() 15 { 16 var inputColor = prompt( 17 "Enter a color name for the " + 18 "background of this page", "" ); 19 document.body.style.backgroundColor = inputColor; 20 } 21 // --> Welcome to our Web site! Function start prompts the user to enter a color and then sets the background to that color. A prompt dialog box is displayed prompting the user to input a color. The color is stored in variable inputColor. The input color is set as the background color.

 2001 Prentice Hall, Inc. All rights reserved. Outline 9 Program Output Initial Output Prompt dialog asking user to enter a background color. Final output with background color selected by the user set.

 2001 Prentice Hall, Inc. All rights reserved. Outline 10 Dynamicstyle2.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Object Model bigText { font-size: 3em; 15 font-weight: bold } smallText { font-size:.75em } <!-- 23 function start() 24 { 25 var inputClass = prompt( 26 "Enter a className for the text " + 27 "(bigText or smallText)", "" ); 28 pText.className = inputClass; 29 } 30 // --> The user is prompted to enter one of the two defined styles to be applied to the text. Two style classes for font are defined.

 2001 Prentice Hall, Inc. All rights reserved. Outline 11 Dynamicstyle2.ht ml Program Output Welcome to our Web site! Font after user decides to apply the bigText style to the text. Dialog prompting user to enter a font style.

 2001 Prentice Hall, Inc. All rights reserved. Outline 12 Dynamicposition. html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " Dynamic Positioning <!-- 14 var speed = 5; 15 var count = 10; 16 var direction = 1; 17 var firstLine = "Text growing"; 18 var fontStyle = [ "serif", "sans-serif", "monospace" ]; 19 var fontStylecount = 0; function start() 22 { 23 window.setInterval( "run()", 100 ); 24 } function run() 27 { 28 count += speed; if ( ( count % 200 ) == 0 ) { 31 speed *= -1; 32 direction = !direction; 33 Function start is used to update the p element’s content. Function setInternal takes in a function name and how often to run that function. Function run will reverse between increasing and decreasing font size and blue and red font color.

 2001 Prentice Hall, Inc. All rights reserved. Outline 13 Dynamicposition. html 34 pText.style.color = 35 ( speed < 0 ) ? "red" : "blue" ; 36 firstLine = 37 ( speed < 0 ) ? "Text shrinking" : "Text growing"; 38 pText.style.fontFamily = 39 fontStyle[ ++fontStylecount % 3 ]; 40 } pText.style.fontSize = count / 3; 43 pText.style.left = count; 44 pText.innerHTML = firstLine + " Font size: " + 45 count + "px"; 46 } 47 // --> <p id = "pText" style = "position: absolute; left: 0; 53 font-family: serif; color: blue"> 54 Welcome! Font size and color will be selected based on the value of speed.

 2001 Prentice Hall, Inc. All rights reserved. Outline 14 Program Output Once count reaches a multiple of 200, the size of the text font starts to shrink by one third.

 2001 Prentice Hall, Inc. All rights reserved. Outline 15 Index.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" 3 " Frames collection The browser window is broken into two horizontal frames. The top frame (upper) displays file top.html. The bottom frame (lower) is initially empty.

 2001 Prentice Hall, Inc. All rights reserved. Outline 16 Top.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " The frames collection <!-- 14 function start() 15 { 16 var text = prompt( "What is your name?", "" ); 17 parent.frames( "lower" ).document.write( 18 " Hello, " + text + " " ); 19 } 20 // --> Cross-frame scripting! Function start takes in a user’s name and writes it in a frame in the browser. The write function is used to write text to the frame in the browser. The parent frame of the current frame is first referenced following that the lower frame is referenced.

 2001 Prentice Hall, Inc. All rights reserved. Outline 17 Program Output Browser prior to user entering a name. Dialog prompt for user to enter name. Browser updated with user name and Hello displayed in bottom frame.

 2001 Prentice Hall, Inc. All rights reserved. Outline 18 Navigator.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " The navigator Object <!-- 14 function start() 15 { 16 if (navigator.appName=="Microsoft Internet Explorer") 17 { 18 if ( navigator.appVersion.substring( 1, 0 ) >= "4" ) 19 document.location = "newIEversion.html"; 20 else 21 document.location = "oldIEversion.html"; 22 } 23 else 24 document.location = "NSversion.html"; 25 } 26 // --> Redirecting your browser to the appropriate page, 32 please wait On load function start is called to determine what browser is being used. Based on this a page specific to that browser is displayed. The browser is Microsoft Internet Explorer. The function appVersion is used to determine which version of IE is used. The browser is Netscape.

 2001 Prentice Hall, Inc. All rights reserved. Outline 19 Program Output The document specific for the Microsoft Internet Explorer browser is displayed. The document specific for the Netscape browser is displayed. (Netscape Communicator browser window © 1999 Netscape Communications Corporation. Used with permission. Netscape Communications has not authorized, sponsored, endorsed, or approved this publication and is not responsible for its content.)

 2001 Prentice Hall, Inc. All rights reserved Summary of the DHTML Object Model Fig DHTML Object Model.

 2001 Prentice Hall, Inc. All rights reserved Summary of the DHTML Object Model

 2001 Prentice Hall, Inc. All rights reserved Summary of the DHTML Object Model