HTML5 Introduction
Upcoming SlideShare
Loading in...5
×
 

HTML5 Introduction

on

  • 2,063 views

An introduction to HTML5 by Olivier Verhoogen, mobile developer at Foreach.

An introduction to HTML5 by Olivier Verhoogen, mobile developer at Foreach.

Statistics

Views

Total Views
2,063
Views on SlideShare
2,063
Embed Views
0

Actions

Likes
1
Downloads
32
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

HTML5 Introduction HTML5 Introduction Presentation Transcript

  • HTML 5
    A probably not so complete introduction
  • The Disclaimer
    I’m not an expert…
    So… Feel free to share your expertise!
    Most of this presentation is a synopsis of the excellent book Dive into HTML5 by Mark Pilgrim.
    An online version of the text can be found at http://diveintohtml5.org/.
    Legal and everything!
  • A bit of motivation
    “HTML was primarily designed as a language for semantically describing scientific documents, although its general design and adaptations over the years have enabled it to be used to describe a number of other types of documents.
    The main area that has not been adequately addressed by HTML is a vague subject referred to as Web Applications. This specification attempts to rectify this, while at the same time updating the HTML specifications to address issues raised in the past few years.”
    from the HTML5 Working Draft (19 October 2010)
  • Can I use it today?
    Detect browser support using Javascript.
    Modernizr can help you out for this.
    The Modernizr homepage will show a feature grid for the current browser.
    Check out your favorite browser at http://www.modernizr.com/.
  • So can I use it today… on the desktop?
    Your mileage may vary…
    This should improve with the release of IE9.
  • So can I use it today… on mobiles?
    Looking good!
  • The topics we’ll cover
    More and less markup
    Drawing things
    Showing videos
    Geolocation
    Offline storage
    The offline application cache
    Microdata
  • The topics we won’t cover
    CSS3
    New form elements
    Web Sockets
    Web Workers
    Web SQL Database
    And many more!
  • Learn by example
    We’ll dissect an example as we go along.
    It will showcase every featured topic.
    It’s a poor man’s mobile application.
    Leverage superior support on mobile platforms.
    (I’m hoping to become a mobile developer someday.)
  • Let’s get started!
  • More and less markup (I)
    A new and simple doctype:
    <!DOCTYPE html PUBLIC
    "-//W3C//DTD XHTML 1.0 Strict//EN“
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1- strict.dtd">
    <!DOCTYPE html>
  • More and less markup (II)
    A new and simple root element:
    <html xmlns="http://www.w3.org/1999/xhtml"
    lang="en" xml:lang="en">
    <html lang="en">
  • More and less markup (III)
    New and simple character encoding selection:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta charset="utf-8" />
  • More and less markup (IV)
    Slightly more simple stylesheets:
    <link rel="stylesheet" href="style-original.css"
    type="text/css" />
    <link rel="stylesheet" href="style-original.css" />
  • More and less markup (V)
    New link types:
    nofollow, prefetch, ...
  • More and less markup (VI)
    New semantic elements:
    <section>, <nav>, <article>, <aside>, <hgroup>, <header>, <footer>, <time>, <mark>, ...
    Be wary: Weirdness may happen when the browser doesn't (yet) recognize these elements!
  • Drawing things (I)
    “The canvas element provides scripts with a resolution-dependent bitmap canvas, which can be used for rendering graphs, game graphics, or other visual images on the fly.”
    from the HTML5 Working Draft (19 October 2010)
  • Drawing things (II)
    Use the <canvas> element to insert a canvas:
    <canvas id="myCanvas" width="300" height="225"/>
  • Drawing things (III)
    Get access to the drawing context via Javascript:
    var myCanvas = document.getElementById("myCanvas");
    var myContext = myCanvas.getContext("2d");
  • Drawing things (IV)
    Draw some rectangles:
    myContext.fillStyle = "rgb(43, 62, 199)";
    myContext.fillRect(0, 0, 300, 225);
    myContext.lineWidth = 5;
    myContext.strokeStyle = "black";
    myContext.strokeRect(0, 0, 300, 225);
  • Drawing things (V)
    Draw some paths:
    myContext.beginPath();
    myContext.moveTo(50, 112);
    myContext.lineTo(240, 112);
    myContext.stroke();
    myContext.beginPath();
    myContext.moveTo(250, 112);
    myContext.lineTo(220, 82);
    myContext.lineTo(220, 142);
    myContext.closePath();
    myContext.fill();
  • Drawing things (VI)
    Draw some text:
    myContext.font = "bold 12px sans-serif";
    myContext.fillText("<canvas> is sweet!", 40, 50);
  • Drawing things (VII)
    Handle some click events:
    function handleClick(clickEvent)
    {
    var x, y;
    if ( clickEvent.pageX != undefined && clickEvent.pageY != undefined )
    {
    x = clickEvent.pageX;
    y = clickEvent.pageY;
    }
    else
    {
    x = clickEvent.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
    y = clickEvent.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }
    x -= myCanvas.offsetLeft;
    y -= myCanvas.offsetTop;
    // You should probably do something useful here.
    }
    myCanvas.addEventListener("click", handleClick, false);
  • Drawing things (VIII)
    Internet Explorer 8 doesn't support canvas.
    It does support drawing via the Vector Markup Language (VML).
    The explorercanvas library implements canvas using VML.
    It does have some limitations.
    Find it at http://code.google.com/p/explorercanvas/
  • Showing videos (I)
    “A video element is used for playing videos or movies.”
    from the HTML5 Working Draft (19 October 2010)
  • Showing videos (II)
    Inserting a video should be as easy as inserting an image:
    Browsers should have built-in support for playing video.
    No third-party plugins should be required.
    Standard formats should exist that are supported by all browsers.
    But...
  • Showing videos (III)
    Surprizingly, no standard formats exist that are supported by all browsers.
    For maximum compatibility you will have to supply content in multiple formats.
    HTML 5 will let you specify multiple files in different formats and have the browser select one it supports.
  • Showing videos (IV)
    Use the <video> element to insert a video:
    <video src="movies/alikeforlife.mp4" width="480"
    height="272" controls />
  • Showing videos (V)
    Provide multiple formats:
    <video width="480" height="272" controls>
    <source src="alikeforlife.mp4"
    type='video/mp4;codecs="avc1.42E01E,mp4a.40.2"' />
    <source src="alikeforlife.ogv"
    type='video/ogg; codecs="theora, vorbis"' />
    </video>
  • Showing videos (VI)
    Compliant browsers ignore non-<source> children of <video> elements.
    A nested <object>tag can be included for backwards compatibility.
    Programmatic control is possible via Javascript.
  • Geolocation (I)
    “The Geolocation API defines a high-level interface to location information associated only with the device hosting the implementation, such as latitude and longitude.”
    from the Geolocation API Candidate Recommendation (7 September 2010)
  • Geolocation (II)
    Request the current position:
    function callback(position)
    {
    var timestamp = position.timestamp;
    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;
    // ...
    }
    navigator.geolocation.getCurrentPosition(callback);
  • Geolocation (III)
    The position is returned asynchronously.
    Location information can come from a number of sources.
    A GPS unit is not necessarily required.
    “User agents must not send location information to Web sites without the express permission of the user.”
    Usually a popup will explicitly ask for permission.
  • Geolocation (IV)
    Do some error handling:
    function errorHandler(error)
    {
    var code = error.code;
    var message = error.message;
    // ...
    }
    navigator.geolocation.getCurrentPosition(callback,
    errorHandler);
  • Geolocation (V)
    Set some options:
    var options =
    {
    enableHighAccuracy: true,
    timeout: 10000,
    maximumAge: 60000
    }
    navigator.geolocation.getCurrentPosition(callback,
    errorHandler, options);
  • Geolocation (VI)
    Do some continuous tracking:
    var ticket = navigator.geolocation.watchPosition(
    callback, errorHandler, options);
    navigator.geolocation.clearWatch(ticket);
  • Geolocation (VII)
    You may want to support additional geolocation frameworks:
    Gears
    Blackberry
    Nokia
    ...
    The geo-location-javascript library provides a unified geolocation interface.
    Find it at http://code.google.com/p/geo-location-javascript/.
  • Offline storage (I)
    “This specification defines an API for persistent data storage of key-value pair data in Web clients.”
    from the Web Storage Working Draft (22 December 2009)
  • Offline storage (II)
    Load and store data via the localStorage object:
    localStorage.setItem("someProperty", "someValue");
    var value = localStorage.getItem("someProperty");
  • Offline storage (III)
    You may prefer associative arrays:
    localStorage["someProperty"] = "someValue";
    var value = localStorage["someProperty"];
  • Offline storage (IV)
    Store information as key/value pairs.
    Values are stored as strings.
    You'll have to coerce the value to the proper type if it's not a string.
    Everything happens client-side.
    Unlike cookies, no data is sent to the server.
    It's even supported in Internet Explorer 8!
  • Offline storage (V)
    The specification suggests an arbitrary limit of 5 megabytes per origin.
    Storage is per domain.
    Cross-directory attacks are possible on shared hosts!
  • The offline application cache (I)
    “In order to enable users to continue interacting with Web applications and documents even when their network connection is unavailable (...) authors can provide a manifest which lists the files that are needed for the Web application to work offline and which causes the user's browser to keep a copy of the files for use offline.”
    from the HTML5 Working Draft (19 October 2010)
  • The offline application cache (II)
    Enable offline use of your web-application:
    All application resources are downloaded into an offline cache when the user visits your webpage.
    The page can then be served from the cache, even when the user is offline.
  • The offline application cache (III)
    A manifest lists the resources of your application:
    CACHE MANIFEST
    # Revision 99
    images/logo.jpg
    index.php
    stylesheet.css
  • The offline application cache (IV)
    You reference the manifest from every HTML file:
    <html manifest="/cache.manifest">
    <!–– ... ––>
    </html>
  • The offline application cache (V)
    The manifest is checked on every page visit.
    When the manifest has changed, the resources are recached.
    This process is automatic.
    Javascript events allow you to know what's going on.
  • The offline application cache (VI)
    You can have three sections in your manifest:
    A cache section.
    Required resources to be stored in the cache.
    A network section.
    Uncached resources that will only be referenced when online.
    A fallback section.
    Resources matching these URL patterns will be satisfied via the network when online, or will be mapped on the specified resource when offline.
  • The offline application cache (VII)
    The manifest file must be served with the text/cache-manifestcontent-type.
    Only resources listed in the manifest can be accessed, even when online.
    The offline cache will only be updated when the manifest file itself changes.
    Adding a revision count to your manifest is a good idea.
    When a new version of your page is cached it will take an additional reload of the page to switch to the new cache.
  • Microdata (I)
    “This mechanism allows machine-readable data to be embedded in HTML documents in an easy-to-write manner, with an unambiguous parsing model.”
    from the HTML Microdata Working Draft (19 October 2010)
  • Microdata (II)
    Add custom-domain semantic information to your HTML markup.
    Make it so that a machine can interpret the information on your webpage within the specified domain.
  • Microdata (III)
    The semantic domain of HTML is constrained to documents.
    It lets you describe such things as sections, headers, paragraphs, etc.
    Via microdata you can add semantic meaning to a specific tag.
    The content of a specific <span> tag might for instance be the name of a person.
  • Microdata (IV)
    A vocabulary defines:
    A specific semantic object, f.i. a Person.
    A number of properties that this semantic object can have, f.i. a name or an email address.
    A vocabulary is identified by means of a URI.
  • Microdata (V)
    How it might look in your HTML code:
    <section itemscope
    itemtype="http://data-vocabulary.org/Person">
    <h1>Contact Information</h1>
    <dl>
    <dt>Name</dt>
    <dd itemprop="name">John Doe</dd>
    </dl>
    </section>
  • Microdata (VI)
    Google's spider interprets microdata.
    Annotated pages will appear semantically formatted in search results.
  • Questions?
  • Thanks!
  • References
    • Dive into HTML5 by Mark Pilgrimhttp://diveintohtml5.org/
    • The Modernizr websitehttp://www.modernizr.com/
    • The HTML5 Working Draft (19 October 2010)http://www.w3.org/TR/2010/WD-html5-20101019/
    • The Geolocation API Candidate Recommendation (7 September 2010)http://www.w3.org/TR/geolocation-API/
    • The Web Storage Working Draft (22 December 2009)http://www.w3.org/TR/webstorage/
    • The HTML Microdata Working Draft (19 October 2010)http://www.w3.org/TR/microdata/