© De Montfort University, 20031 Document Object Model Howell Istance School of Computing De Montfort University.

Slides:



Advertisements
Similar presentations
Sue Wills July Objects The JavaScript language is completely centered around objects, and because of this, it is known as an Object Oriented Programming.
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Session 11 Dynamic HTML: Event Model and Filters Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
The Web Warrior Guide to Web Design Technologies
Tutorial 16 Working with Dynamic Content and Styles.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
© De Montfort University, Javascript control of players Howell Istance.
1 JavaScript Document Object Model & Events. 2 Document Object Model (DOM) JavaScript access to the elements of an HTML document. An object hierarchy.
Page 1 of 39 Javascript Chapters 13, 14 Vadim Parizher Computer Science Department California State University, Northridge Fall 2003 Slides from text Book.
Computer Science 103 Chapter 4 Advanced JavaScript.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Events.
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
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.
Unobtrusive JavaScript
Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript & DOM Client-side scripting. JavaScript JavaScript is a tool to automate client side (which is implemented using HTML so far) JavaSript syntax.
Lesson 19. JavaScript errors Since JavaScript is an interpreted language, syntax errors will usually cause the script to fail. Both browsers will provide.
UFCEWT-20-3 Advanced Topics in Web Development Lecture 4 : JavaScript, Browsers & the HTML DOM-API.
DOM and JavaScript Aryo Pinandito.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
1 Dynamic HTML III: Event Model Introduction Event model –Scripts respond to user actions and change page accordingly Moving mouse Scrolling screen.
Creating an Animated Web Page
Working with Objects Creating a Dynamic Web Page.
CITS1231 Web Technologies JavaScript and Document Object Model.
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
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
JavaScript, Part 3 Instructor: Charles Moen CSCI/CINF 4230.
5.2 DOM (Document Object Model). 2 Motto: To write it, it took three months; to conceive it three minutes; to collect the data in it — all my life. —F.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Dynamic HTML: Event Model Outline 16.1Introduction 16.2Event ONCLICK 16.3Event ONLOAD.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 20 – Dynamic HTML: Object Model and Collections Outline 20.1Introduction 20.2Object Referencing.
JavaScript IV ECT 270 Robin Burke. Outline DOM JS document model review W3C DOM.
DHTML: Working with Objects Creating a Dynamic Web Page.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Scripting and Interactivity 이병희
JavaScript DOM.
CSS1 Dynamic HTML Objects, Collections & Events. CSS2 Introduction Dynamic HTML treats HTML elements as objects. Element’s parameters can be treated as.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Dynamic HTML: Event Model Outline 16.1Introduction 16.2Event ONCLICK 16.3Event ONLOAD.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
Understanding JavaScript and Coding Essentials Lesson 8.
JS: Document Object Model (DOM) DOM stands for Document Object Model, and allows programmers generic access to: DOM stands for Document Object Model, and.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 15 – Dynamic HTML: Object Model and Collections Outline 15.1Introduction 15.2Object Referencing.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JAVASCRIPT A quick review. True False ■The DOM is a standardized way of referring to parts of a Web page. ■TRUE ■In the DOM, attributes have their own.
Internet & World Wide Web How to Program, 5/e.  JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events.
The Web Wizard’s Guide To DHTML and CSS Chapter 2 A Review of CSS2 and JavaScript.
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.
THE DOM.
DHTML.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Applied Online Programming
Chapter 14: DHTML: Event Model
JavaScript Introduction
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
Introduction to Programming the WWW I
© 2015, Mike Murach & Associates, Inc.
Introduction to DHTML, the DOM, JS review
Presentation transcript:

© De Montfort University, Document Object Model Howell Istance School of Computing De Montfort University

© De Montfort University, What is the DOM? DOM is Document Object Model A standard way to refer to objects on a Web page The W3C DOM1 replaces proprietary DOMs from Netscape and Microsoft As the version (and source) of DOM varies between browsers, writing robust code to run on any browser is problematical!

© De Montfort University, Nodes in DOM An object in DOM1 is called a node. Same node types as xml Element nodes (,, etc.) Text nodes (text contained by element nodes) Attribute nodes (align=“center”)

© De Montfort University, Visualising Nodes

© De Montfort University, Things to do with nodes Change the text of nodes Add and remove text nodes Create element nodes to dynamically style content Change the value of attribute nodes Test for browser

© De Montfort University, Span elements and id attributes this is some text, doesn’t really matter what this is some text, doesn’t really matter what Methods and properties of object accessed via name “pText” New object “oneword” of class span created with text node “doesn’t”, parent is “pText”

© De Montfort University, Object hierarchy ‘window’ object contains –‘document’ object –‘navigator’ object Objects have properties and methods – these vary according to the version and source of DOM used Objects contain children objects Objects manipulated using script (JavaScript usually)

© De Montfort University, DOM Nodes function changeGreeting(){ var theNode = document.getElementById("greeting"); var newGreeting = window.prompt("Type a greeting.","Hej!"); theNode.firstChild.nodeValue = newGreeting; } Hi! My name is Joe Bloggs Change Greeting!

© De Montfort University, Things to note Use of span to create object named “greeting” document method ( GetElementById() ) to get the span node window method ( prompt() ) to open a message box and return a value Use of firstChild to reference child node of theNode Use of nodeValue property to access value of text node

© De Montfort University, function getBrowserInfo(){ var UA = navigator.userAgent.toLowerCase(); var isIE = (UA.indexOf('msie')>=0) ? true : false; if (!isIE){ var isNS = (UA.indexOf('mozilla')>=0)?true :false;} else{ var isNS = false;} var version = navigator.appVersion; var output = " "; output += "User Agent: " + UA + " "; output += "Internet Explorer " + isIE + " "; output += "Netscape Navigator " + isNS + " "; output += "Version: " + version + " "; output += " "; return output; } document.write(getBrowserInfo());

© De Montfort University, Things to note… Use of Navigator properties, userAgent and appVersion Syntax of conditional assignment statement Boolean variables isIE and isNS which can be used in other functions when using a browser-specific technology

© De Montfort University, Navigator Object –Supported by Netscape Navigator DOM and Internet Explorer DOM –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

© De Montfort University, Building a Playlist function start(){ var theNode = document.getElementById("playlist"); for(n = 0; n< playlistitems.length; n++){ var newelem= document.createElement("li"); var thistextnode = document.createTextNode(playlistitems[n].artist_name); newelem.appendChild(thistextnode); theNode.appendChild(newelem); } My JukeBox

© De Montfort University, Things to note… (assumes the existence of an Array, called playlistitems, containing url of sound clip, url of artist picture, artist_name) Use of document.createElement() to create new li element Use of theNode.appendChild() to add this element to the ol element called ‘ playlist ’ Use of for loop to iterate over the playlistitems array Method is called in response to the ‘onload’ event occuring in the ‘body’ element of the document.

© De Montfort University, innerHTML method Enables a string of HTML to be added as the content of a named object Very useful, but this is an IE method only – doesn’t work in Netscape Navigator playliststring = "Play List... "; for(n = 0; n< playlistitems.length; n++){ playliststring = playliststring + " + playlistitems[n].artist_name; } playliststring = playliststring + " "; playlist.innerHTML = playliststring;

© De Montfort University, Event ONLOAD ONLOAD event –Fires when element finishes loading successfully –Often used in BODY tag Initiate scripts as soon as page loads

© De Montfort University, DHTML Event Model function updateMouseCoordinates(){ coordinates.innerText = event.srcElement.tagName + "(" + event.offsetX + "," + event.offsetY + ")"; } (0,0)

© De Montfort University, Tracking the Mouse with Event ONMOUSEMOVE ONMOUSEMOVE event –Fires constantly whenever mouse in motion event object –Contains info about triggered event –srcElement Pointer to element object that triggered event –offsetX and offsetY Give location of mouse cursor relative to top-left corner of object in which event triggered

© De Montfort University, Object tag… IMG element, ‘empty’- no content, only attributes Netscape provided EMBED tag, adopted by MS, but not standard HTML (ie not recognised by W3C) In HTML 4.0, OBJECT tag provided to accommodate new media types OBJECT has content, content is NOT the media element content only displayed if user-agent is unable to display the object

© De Montfort University, Example of use of Object tag.. <OBJECT data = “movies/clip2.mov” type = “video/quicktime”> <OBJECT data = “images/still2.jpg” type = “image/jpg”> A 5 second video clip

© De Montfort University, Example of use of Object tag.. <EMBED SRC="rtsp://lapis/hoi/rory_irishtour.rm" NAME= "jukebox2" TYPE="audio/x-pn-realaudio-plugin" CONSOLE="Clip1" CONTROLS="ControlPanel" HEIGHT=36 WIDTH=350 AUTOSTART=false>

© De Montfort University, What the Object tag tries to do…