COMP3220 Web Infrastructure COMP6218 Web Architecture

Slides:



Advertisements
Similar presentations
The Document Object Model
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Introduction to HTML5 Programming donghao. HTML5 is the New HTML Standard New Elements, Attributes. Full CSS3 Support Video and Audio 2D/3D Graphics Local.
Document Object Model. Lecture 18 The Document Object Model (DOM) is not a programming language It is an object-oriented model of web documents Each.
Bartosz Kowalski Software Developer CERN. Presentation outline -HTML : introduction and history -HTML5 : -History and philosophy -New features -Structure.
CS 415 N-Tier Application Development By Umair Ashraf July 16,2013 National University of Computer and Emerging Sciences Lecture # 12 HTML/ XHTML/ HTML5.
Canvas, SVG, Workers Doncho Minkov Telerik Corporation
HTML 5 New Standardization of HTML. I NTRODUCTION HTML5 is The New HTML Standard, New Elements New Attributes Full CSS3 Support Video and Audio 2D/3D.
The Document Object Model (DOM) & Asynchronous Javascript And XML (AJAX) : an introduction UFCEKG-20-2 : Data, Schemas and Applications.
Enterprise Application Integration – Web Collaboration and Standardisation Enterprise Application Integration – Web Collaboration and Standardisation.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Internet Applications Spring Review Last week –MySQL –Questions?
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.
JS: Document Object Model (DOM)
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
Administration, Coverage, Review. Exam Administration Midterm exam is in class from 5:15 – 6:30PM on Thursday Feb 20 th. The exam is open book and open.
Client side web programming Introduction Jaana Holvikivi, DSc. School of ICT.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
Building Rich Web Applications with Ajax Linda Dailey Paulson IEEE – Computer, October 05 (Vol.38, No.10) Presented by Jingming Zhang.
Session: 1. © Aptech Ltd. 2Introduction to the Web / Session 1  Explain the evolution of HTML  Explain the page structure used by HTML  List the drawbacks.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Introduction to the Document Object Model Eugenia Fernandez IUPUI.
INNOV-7: Building a Richer UI for the Browser Chris Skeldon Senior Solution Consultant.
1 Javascript DOM Peter Atkinson. 2 Objectives Understand the nature and structure of the DOM Add and remove content from the page Access and change element.
(1) JavaScript. (2) JavaScript vs. Java JavaScript and Java are completely different Java, invented by Sun in 1995, is a complex programming language.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
Create Element, Remove Child. The Document Tree Document Element Root Element Element Element Element Element Text: HelloWorld Attribute “href”
JS: Document Object Model (DOM) DOM stands for Document Object Model, and allows programmers generic access to: DOM stands for Document Object Model, and.
XML DOM Week 11 Web site:
Agenda * What is HTML5 -- Its history and motivation * HTML/XHTML as Human / Machine Readable Format * HTML and its related technologies * Brief summary.
Development of Internet Applications HTML5 Ing. Jan Janoušek 7.
XHTML. What Is XHTML? XHTML stands for EXtensible HyperText Markup Language XHTML is almost identical to HTML XHTML is stricter than HTML XHTML is HTML.
The HTML5 logo was introduced by W3C in 2010
THE DOM.
DHTML.
Web Technologies Computing Science Thompson Rivers University
Project 1 Introduction to HTML.
Internet Technologies
Unit 4 Representing Web Data: XML
Internet of the Past.
WEB SERVICES From Chapter 19 of Distributed Systems Concepts and Design,4th Edition, By G. Coulouris, J. Dollimore and T. Kindberg Published by Addison.
z/Ware 2.0 Technical Overview
CS5220 Advanced Topics in Web Programming JavaScript and jQuery
Introduction to the Document Object Model
DOM Robin Burke ECT 360.
Project 1 Introduction to HTML.
Application with Cross-Platform GUI
XML in Web Technologies
Representational State Transfer
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
CISC103 Web Development Basics: Web site:
WEB API.
Chapter 7 Representing Web Data: XML
JavaScript Introduction
Week 11 Web site: XML DOM Week 11 Web site:
DOM Document Object Model.
HTML A brief introduction HTML.
Asynchronous Javascript And XML
Introduction to Programming the WWW I
Introduction to HTML5 and WebSockets.
JavaScript & jQuery AJAX.
WEB SERVICES From Chapter 19, Distributed Systems
Web Technologies Computing Science Thompson Rivers University
Carnegie Mellon Heinz College
Presentation transcript:

COMP3220 Web Infrastructure COMP6218 Web Architecture HTML5 APIs COMP3220 Web Infrastructure COMP6218 Web Architecture Dr Nicholas Gibbins – nmg@ecs.soton.ac.uk 2017-2018

HTML as application platform HTML5 APIs fall into three broad classes: Document content Document Object Model, Canvas Browser services XMLHttpRequest, WebSockets Web Storage, IndexedDB Web Workers Hardware access Geolocation, Media Capture, Vibration, Battery Status

A word on standardisation Status of APIs is highly variable Some are W3C recommendations Some are WHATWG “living standards” Some are both (but equivalent) Some are both (but differ) Browser support is variable Write defensive code – check for API support before calling it

Document Object Model

Document Object Model (DOM) Standard API for accessing and manipulating XML and HTML Document represented as a hierarchy of objects of type Node Root of hierarchy is an object of type Document Node interface is the key to understanding DOM Core Methods for basic access and manipulation of hierarchy Other types derived from Node add further methods Different versions of DOM for different languages Extensions of DOM Core

Selected Node type hierarchy Document Element Attr Text EntityReference

Node interface – attributes parentNode childNodes firstChild lastChild previousSibling nextSibling attributes parent Node previous Sibling this node next Sibling first Child last Child childNodes

Node interface – methods insertBefore(newChild, refChild) Inserts newChild into list of children after refChild replaceChild(newChild, oldChild) Replaces oldChild in list of children with newChild removeChild(oldChild) Removes oldChild from list of children appendChild(newChild) Adds newChild to the end of the list of children cloneNode(deep) Returns a duplicate of the node (which may be a deep copy)

Document interface – methods getElementsByTagName(tagname) Get a list of all elements with the given tag name getElementById(elementId) Get the element with the given ID createElement(tagName) createAttribute(name) createTextNode(data) createEntityReference(name)

Element interface – methods getAttribute(name) Returns value of named attribute setAttribute(name, value) Sets value of named attribute getElementsByTagName(name) Get a list of all descendant elements with the given tag name

Canvas

Canvas 2D Context API for drawing graphics via JavaScript Uses <canvas> element as container for 2d context Animation via JavaScript (compare with declarative animation in SVG)

Canvas example – canvas.html <!DOCTYPE html> <html> <head> <title>Canvas example</title> </head> <body> <canvas id='canvas' width='600' height='300'> Canvas not supported </canvas> <script src='canvas.js'></script> </body> </html> fallback content external script

Canvas example – canvas.js var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); context.fillStyle = 'red'; context.fillRect(10,10,110,60); context.font = '32pt Lucida Sans'; context.strokeStyle = 'blue'; context.strokeText("Lorem Ipsum", 40, 40);

XMLHttpRequest

XMLHttpRequest API for fetching representations of resources Asynchronous Register onload handler function for response AJAX – Asynchronous JavaScript and XML

XMLHttpRequest example function handler() { if (this.status == 200 && this.responseXML != null { // success } else { // failure } } var client = new XMLHttpRequest(); // Register handler client.onload = handler; // Construct request client.open("GET", ”http://example.org/srv"); // Send request client.send();

Web Sockets

Web Sockets Three issues with XMLHttpRequest: Connection is not persistent Repeated requests require TCP setup and teardown Communication always initiated by client No pushing of messages from the server Bound only to HTTP/HTTPS Web Sockets is a modern replacement for XMLHttpRequest Supports multiple transport protocols

Web Sockets example var connection = new WebSocket('ws://example.org/srv', [‘http', 'xmpp']); connection.onmessage = function (e) { console.log('Server: ' + e.data); }; connection.send('...data...');

Web Storage

Web Storage Cookies used to store key-value data in the browser HTTP-based mechanism (Cookie: header) Breaks stateless nature of HTTP Web Storage is a more principled replacement Separate storage area for each origin (web page) Non-persistent storage (Window.sessionStorage) Persistent storage (Window.localStorage)

Web Storage example localStorage.setItem('email', 'fred@example.org'); localStorage.getItem('visitCount'); sessionStorage.getItem('query');

IndexedDB

IndexedDB Web Storage API only useful for key-value data IndexedDB is a more sophisticated web browser database: Asynchronous Transaction support Structured (JSON) data (c.f. CouchDB, MongoDB, etc)

IndexedDB example var db; var request = indexedDB.open("books"); request.onsuccess = function() { db = request.result; };

IndexedDB example var trans = db.transaction("books", "readwrite"); var store = trans.objectStore("books"); store.put({title: "HTML5 for Dummies", isbn: 123456}); store.put({title: "Starting HTML5", isbn: 234567}); store.put({title: "HTML5 Revealed", isbn: 345678}); trans.oncomplete = function() { // Called when all requests have succeeded // (the transaction has committed) };

Web Workers

Web Workers Trend in Web scripting is towards asynchrony XMLHttpRequest Web Sockets Web Storage JavaScript browser environment is single-threaded Compute-intensive tasks affect responsiveness of scripts Web Workers provides multi-threading for JavaScript Asynchronous handling of results

Web Workers example // Main thread: var searcher = new Worker('searcher.js'); searcher.postMessage(query); searcher.onmessage = function (event) { // Process result from the worker thread }; // searcher.js: onmessage = function (event) { // Process message received from the main thread };

Geolocation

Geolocation Allows a script to determine client location One-off (getCurrentPosition()) Ongoing (watchPosition()) Location information service independent GPS GSM/CDMA Wi-Fi

Geolocation example navigator.geolocation.getCurrentPosition(success); function success(pos) {   console.log("Latitude: " + pos.coords.latitude); console.log("Longitude: " pos.coords.longitude); }

Next Lecture: Cascading Style Sheets