Internet Technology 1 Presentation 9: DHTML. Ingeniørhøjskolen i Århus Slide 2 Agenda What is DHTML and what is it used for? DOM and the Cross Browser.

Slides:



Advertisements
Similar presentations
Web 2.0 Programming 1 © Tongji University, Computer Science and Technology. Web Web Programming Technology 2012.
Advertisements

Fawaz Ghali AJAX: Web Programming's Toy.
Essentials for Design JavaScript Level One Michael Brooks
JavaScript and AJAX Jonathan Foss University of Warwick
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
A really fairly simple guide to: mobile browser-based application development (part 1) Chris Greenhalgh G54UBI / Chris Greenhalgh
Pemrograman Teknologi Internet W09: DOM & DHTML. 2 Objectives DOM: DOM: DOM Nodes & Trees DOM Nodes & Trees Traversing & Modifying DOM Trees Traversing.
Web Server Programming
Introduction to JavaScript Module 1 Client Side JS Programming M-GO Sponsored By
© 2007 IBM Corporation IBM Emerging Technologies Enabling an Accessible Web 2.0 Becky Gibson Web Accessibility Architect.
Server-Side vs. Client-Side Scripting Languages
AJAX Presented by: Dickson Fu Dimas Ariawan Niels Andreassen Ryan Dial Jordan Nielson CMPUT 410 University of Alberta 2006.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Cloud Computing Lecture #7 Introduction to Ajax Jimmy Lin The iSchool University of Maryland Wednesday, October 15, 2008 This work is licensed under a.
Dynamic Web Pages Bert Wachsmuth. Review  Internet, IP addresses, ports, client-server, http, smtp  HTML, XHTML, XML  Style Sheets, external, internal,
Inline, Internal, and External FIle
A closer look Dynamic Webpages Jessica Meyerson March 1, 2011.
© 2006 by IBM 1 How to use Eclipse to Build Rich Internet Applications With PHP and AJAX Phil Berkland IBM Software Group Emerging.
Web Design Basic Concepts.
CST JavaScript Validating Form Data with JavaScript.
DHTML - Introduction Introduction to DHTML, the DOM, JS review.
© 2008 IBM Corporation Emerging Internet Technologies Real World Accessibility with ARIA Becky Gibson Web Accessibility Architect.
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
JavaScript & jQuery the missing manual Chapter 11
ASP.NET + Ajax Jesper Tørresø ITNET2 F08. Ajax Ajax (Asynchronous JavaScript and XML) A group of interrelated web development techniques used for creating.
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
DOM and JavaScript Aryo Pinandito.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
AJAX Making Dynamic Web pages more Dynamic Jim Hendricks April 25th, 2006.
CITS1231 Web Technologies JavaScript and Document Object Model.
The Document Object Model. The Web B.D, A.D. They aren’t web pages, they’re document objects A web browser interprets structured information. A server.
Client side web programming Introduction Jaana Holvikivi, DSc. School of ICT.
Flash & JavaScript Mariela Hristova October 19, 2004 INF 385E – Fall 2004 – School of Information.
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
JavaScript, Part 3 Instructor: Charles Moen CSCI/CINF 4230.
JavaScript. Overview Introduction: JavaScript basics Expressions and types Expressions and types Arrays Arrays Objects and Associative Arrays Objects.
An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
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.
 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.
Ventsislav Popov Crossroad Ltd.. 1. What is AJAX?  AJAX Concept  ASP.NET AJAX Framework 2. ASP.NET AJAX Server Controls  ScriptManager, UpdatePanel.
1 Geospatial and Business Intelligence Jean-Sébastien Turcotte Executive VP San Francisco - April 2007 Streamlining web mapping applications.
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 7.
Telerik Software Academy ASP.NET Web Forms Telerik Software Academy ASP.NET Web Forms.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
Cs332a_chapt10.ppt CS332A Advanced HTML Programming DHTML Dynamic Hypertext Markup Language A term describing a series of technologies Not a stand-a-lone.
By Tharith Sriv. To write a web page you use: HHTML (HyperText Markup Language), AASP (Active Server Page), PPHP (HyperText Preprocessor), JJavaScript,
Rich Internet Applications 3. Client JavaScript. Document Object Model (DOM) The DOM, is an interface that allows scripts or programs to access and manipulate.
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
Introduction to the World Wide Web & Internet CIS 101.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 15 – Dynamic HTML: Object Model and Collections Outline 15.1Introduction 15.2Object Referencing.
Open Solutions for a Changing World™ Eddy Kleinjan Copyright 2005, Data Access WordwideNew Techniques for Building Web Applications June 6-9, 2005 Key.
G046 – Lecture 2A Recognising Web-Technologies Mr C Johnston ICT Teacher
DHTML.
ASP.NET AJAX – Basics Svetlin Nakov Telerik Corporation
Application with Cross-Platform GUI
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
Tutorial 6 Creating Dynamic Pages
Introduction to DHTML, the DOM, JS review
Presentation transcript:

Internet Technology 1 Presentation 9: DHTML

Ingeniørhøjskolen i Århus Slide 2 Agenda What is DHTML and what is it used for? DOM and the Cross Browser Issues Properties og Collections Dynamic style, content and position Events Examples AJAX NOTICE: –It is not possible to cover all possibilities of modern DHTML

Ingeniørhøjskolen i Århus Slide 3 DHTML DHTML = Dynamic HTML – Client Side NOT a W3C Recommendation DHTML = (X)HTML + CSS + JavaScript + DOM –HTML (4.0+), CSS (1.0+), DOM (1+) XHTML, CSS, JavaScript and DOM has already been introduced Unifying these leads to dynamic content

Ingeniørhøjskolen i Århus Slide 4 What is Dynamic HTML Used for? Creating more dynamic & user freindly sites –script: style, position & content Validation of user input (already displayed during JS) Minimize Server Load Dynamic menu structures More ”stable” GUI (AJAX) Dynamic Help ”Rollover” graphics Event controlling = ”Windows”-like user interface -> More possibilities– e.g. browser based HTML editor Alternatives: Flash/Shockwave, Java Applets, ActiveX and other plug-in technologies

Ingeniørhøjskolen i Århus Slide 5 How do we use DHTML Using the DOM API we access XHTML elements We subscibe for ”events” (as in Windows) – and react using eventhandlers using e.g.… … JavaScript (or similar scripting language) used for manipulating the elements

Ingeniørhøjskolen i Århus Slide 6 DOM DOM: Document Object Model – / / W3C: –Standard for accessing structured doucments –Core DOM used for XML –HTML DOM used for HTML –Representation of a document as a tree structure –API’s for e.g. JavaScript, Java, C++, C#, CLS

Ingeniørhøjskolen i Århus Slide 7 DOM Tree Structure Tree structure of a document

Ingeniørhøjskolen i Århus Slide 8 Firefox 2 DOM Inspector

Ingeniørhøjskolen i Århus Slide 9 DOM Versions / Levels DOM level 0: –Browser Object Model (BOM) –Pre DOM standardization –De facto standard –Each vendor has its own –Supports e.g. FORM validation DOM level 1: –Recommandation in October 1998 –All HTML & XML elementer are objects in a trestructure –May be manipulated with and added to DOM level 2: –Recommandation Novemeber 2000 –Event handling included. (eg OnClick), XML Namespaces DOM level 3 –Extensions and added standardization of more of the existing functionalities

Ingeniørhøjskolen i Århus Slide 10 Cross Browser Compatibility Issues Different Vendors supports DOM (and CSS, HTML, XML, Graphics etc) differently Do not expect browsers to be W3C compliant Cross Browser Compatibility –Manual –Difficult –Expensive

Ingeniørhøjskolen i Århus Slide 11 IE4 vs NN4 DOM NN4: function aFunction(){ document.layers.ElmRef.left=300; document.layers.ElmRef.top=300; } A XHTML LAYER Container ELement IE4: function aFunction(){ document.all.ElmRef.left=300; document.all.ElmRef.top=300; } A XHTML DIV Container ELement

Ingeniørhøjskolen i Århus Slide 12 DOM Browser Support Warning: - This is data from Wikipedia.com - -Please check references! -Check vendors

Ingeniørhøjskolen i Århus Slide 13 Solving Cross Browser Problems Cross Browser DHTML Compatibility check –Ex: –Check for which browser is being used OR which objects are supported (last is most common) Browser Detect: –If (IE) {…} else if (NetScape) {…} Object Detect: – if (document.images) { do something with the images array } –if (window.focus) window.focus()

Ingeniørhøjskolen i Århus Slide 14 Cross Browser Toolkits Toolkits available for Crow Broswer resolving Wraps different browser behavior in API Example: –DOJO (since 2004) –Dojo Foundation: Non-profi organization –Open source JavaScript toolkit –BSD License and Academic Free License – Can be done server side as well (.NET, JSF)

Ingeniørhøjskolen i Århus Slide 15 Read more on DOM DEITEL is too loose Read more at – – –

Ingeniørhøjskolen i Århus Slide 16 Properties for Elements In a DOM all elements have the following attributtes –id –tagName –className –style –children –parentElement Which may be used for identification, manipulation and navigation

Ingeniørhøjskolen i Århus Slide 17 DHTML API / DOM All Elements are accesed via the DOM In JavaScript lecture, we used document.forms to access user data for validation This is called a ”Collection” – there are many collections for access

Ingeniørhøjskolen i Århus Slide 18 Important Collections in DHTML API / DOM ”all” collection (fra IE4) (hedder layer i NS4) –All Scriptable Elements ”children” collection –All HTML elements nested in a given element ”forms” collection –All Form elements in a given element ”frames” collection –Ussed for frame access Several others (see previous slide)

Ingeniørhøjskolen i Århus Slide 19 af 51 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.

Ingeniørhøjskolen i Århus Slide 20 af 51 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 !.

Ingeniørhøjskolen i Århus Slide 21 Three Properties we may Change For each element we may change: –Style –Content –Position Giving us (in effect) complete control of the page

Ingeniørhøjskolen i Århus Slide 22 Dynamic Style Changing an elements style dynamic … document.all.para1.style.color=’red’; document.all.para1.style.backgroundColor=’white’; document.all.para1.style.className=’smallFonts’; … … This is a text

Ingeniørhøjskolen i Århus Slide 23 Dynamic Content Content may be changed dynamic … document.all.para1.innerText=’a new text’; document.all.para1.innerHTML=’ a new text ’; … … This is content which will be changed

Ingeniørhøjskolen i Århus Slide 24 Dynamic Positioning We may change the x,y position dynamically … document.all.afs1.style.left=’200px’; … … This section may be moved dynamically In effect: animation is possible

Ingeniørhøjskolen i Århus Slide 25 Frames Usefull Frames collection Parent for moving up and Frames for down

Ingeniørhøjskolen i Århus Slide 26 af 51 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.

Ingeniørhøjskolen i Århus Slide 27 af 51 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. What happens here?

Ingeniørhøjskolen i Århus Slide 28 af 51 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.

Ingeniørhøjskolen i Århus Slide 29 DHTML Events Similar to Windows Event Model Events can capture user / browser interaction –Mouse movements / clicks, –onclick, onmouseover, onfocus and more Also used for capturing system events –onload, onerror, onbounce

Ingeniørhøjskolen i Århus Slide 30 af 51 Onload.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " DHTML Event Model - onload <!-- 13 var seconds = 0; function startTimer() { 16 // 1000 milliseconds = 1 second 17 window.setInterval( "updateTime()", 1000 ); 18 } function updateTime() { 21 seconds++; 22 soFar.innerText = seconds; 23 } 24 // --> Seconds you have spent viewing this page so far: Function startTimer will call function updateTime every 1000 milliseconds. Method window.setInterval is used to invoke function updateTime every second. Function updateTime sets the innerText property of the element with soFar as an id to the number of seconds that have elapsed since loading. The onload event executes when an element finishes loading.

Ingeniørhøjskolen i Århus Slide 31 af 51 Program Output The page will dynamically update the number of seconds that have elapsed since the page has loaded every second.

Ingeniørhøjskolen i Århus Slide 32 af 51 Event Bubbling All events ”bubbles” from a child element up to its ”parent” element – and continues to root element This behavior may be changed: –event.cancelBubble=true

Ingeniørhøjskolen i Århus Slide 33 af 51 Bubbling.html 1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 " DHTML Event Model - Event Bubbling <!-- 14 function documentClick() 15 { 16 alert( "You clicked in the document" ); 17 } function paragraphClick( value ) 20 { 21 alert( "You clicked the text" ); if ( value ) 24 event.cancelBubble = true; 25 } document.onclick = documentClick; 28 // --> By setting the cancelBubble method to true, disables event bubbling.

Ingeniørhøjskolen i Århus Slide 34 af 51 Bubbling.html Program Output Click here! 35 Click here, too! Clicking on the first p element triggers line 27 because the onclick event has bubbled up to the document level. Clicking on the second p element passes a value of true to function paragraphClick, which will disable the event bubbling for this event.

Ingeniørhøjskolen i Århus Slide 35 af 51 DHTML Events I

Ingeniørhøjskolen i Århus Slide 36 af 51 DHTML Events II

Ingeniørhøjskolen i Århus Slide 37 af 51 DHTML Events III

Ingeniørhøjskolen i Århus Slide 38 Events Illustrating Example – Study the link – try it out

Ingeniørhøjskolen i Århus Slide 39 DHTML Usage Examples Deitel illustrates a few –Image Change on mouse ”hover” (onmouseover) –Dynamic help for form fields (onfocus, onblur) –Validation (as seen before) Many possibilites –Dynamic menues Editing Facilities (see next) –Dynamic table sorting –Filters & Transitions

Ingeniørhøjskolen i Århus Slide 40 DHTML Editor Example Greeting Card Editor Example – ive/en-us/dnaredcom/html/dhtmledcom.asphttp://msdn.microsoft.com/archive/default.asp?url=/arch ive/en-us/dnaredcom/html/dhtmledcom.asp – ive/en-us/dnaredcom/html/cncpt.asphttp://msdn.microsoft.com/archive/default.asp?url=/arch ive/en-us/dnaredcom/html/cncpt.asp Using an ActiveX component – only IE 5.5 > Combined with server side = Windows like

Ingeniørhøjskolen i Århus Slide 41

Ingeniørhøjskolen i Århus Slide 42 Open Source Editor FCKEditor – Open source (Commercial License exists) Easy to implement with ASP,PHP,JSP,.NET Demo at: –

Ingeniørhøjskolen i Århus Slide 43 Dynamic Menues Simple Examples – Commercial Example: – DoJo: –

Ingeniørhøjskolen i Århus Slide 44

Ingeniørhøjskolen i Århus Slide 45

Ingeniørhøjskolen i Århus Slide 46

Ingeniørhøjskolen i Århus Slide 47

Ingeniørhøjskolen i Århus Slide 48 Firebug

Ingeniørhøjskolen i Århus Slide 49 AJAX / XML HttpRequestObject AJAX = Asynchronous JavaScript And XML Coined by Jesse James Garrett Feb Is actually DHTML – with async server communication Widespread support Not W3C Usages: –Partial-page-update Pattern –Minimizes HTML page loading operations (no need for frames) –Real Time Form Data Validation –Continuous Data Updates (refreshing) –Advanced User Interface Controls (master detail etc)

Ingeniørhøjskolen i Århus Slide 50 Ajax Overview

Ingeniørhøjskolen i Århus Slide 51 Pros & Cons Pros –Bandwith: Reduces Server Post-back usage (Round-tripping anti- pattern) –GUI: “Windows-like” rich user interfaces, more smooth operation –Design: may encourage programmers to further separate content from presentation Cons: –Breaks HTTP convention – higher complexity – browser navigation –Overly Complex OR “magic” components / toolkits –Relies heavy on DHTML/JS – problems with some browsers –Search Engine integration (as in frames) is problematic –Browser Navigation problematic

Ingeniørhøjskolen i Århus Slide 52 AJAX Support The XMLHttpRequest object supported in –Internet Explorer 5.0+, –Safari 1.2, –Mozilla 1.0 / Firefox, –Opera 8+, –Netscape 7 Usually: get a complete framework

Ingeniørhøjskolen i Århus Slide 53 AJAX Frameworks Simple AJAX: – (HttpRequestObject) – JavaScript based AJAX Frameworks –CleanAJAX: –Mootools Server–side based AJAX Frameworks –Microsoft ASP.NET AJAX: (video: ) –Java AJAX (Echo): –PHP AJAX (AJASON):