161
[email protected] HTML 5 The New Standard For HTML

Learn html5

Embed Size (px)

Citation preview

Page 1: Learn html5

[email protected]

HTML 5 The New Standard For HTML

Page 3: Learn html5

[email protected]

HTML

[New] Tags

JavaScript

APIs

HTML5

Page 8: Learn html5

[email protected]

<!DOCTYPE>

<!DOCTYPE>

<!DOCTYPE>

<!DOCTYPE>SGML(Standard

Generalized Markup Language)

Page 9: Learn html5

[email protected]

<!DOCTYPE>(cont’d)

Page 11: Learn html5

[email protected]

<article> <aside> <bdi> <command> <details> <summary>

<figure> <figcaption> <footer> <header> <hgroup> <mark> <meter> <nav> <progress> <ruby> <rt> <rp> <section> <time> <wbr>

<audio> <video> <source> <embed> <track>

<datalist> <keygen> <output>

Page 13: Learn html5

[email protected]

<div>

Page 14: Learn html5

[email protected]

<div>

Page 15: Learn html5

[email protected]

<div id= "header">

<ul id="nav"> </ul>

</div>

<div id="content">

<div id="blogpost">

<h1>This is my Blogpost</h1>

<p>This is my first paragraph.</p>

</div>

</div>

<div id="sidebar" >

<div id="blogroll">

<p>My blogroll Content.</p>

</div>

</div>

<div id="footer">

<p>My Footer Content.</p>

</div>

Page 16: Learn html5

[email protected]

<header>

<nav></nav>

</header>

<div id="content">

<article id="blogpost">

<section>

<h1>This is my Blogpost</h1>

<p>This is my first paragraph.</p> </section>

</article>

</div>

<div id="sidebar">

<aside id="blogroll">

<p>My blogroll Content.</p>

</aside>

</div>

<footer>

<p>My Footer Content.</p>

</footer>

Page 17: Learn html5

[email protected]

<div>

ID

Page 19: Learn html5

[email protected]

windownavigator

Page 20: Learn html5

[email protected]

<script src="modernizr.min.js"></script>

modernizr_init()

Page 21: Learn html5

[email protected]

Modernizr.video true

false

if (Modernizr.video) {

// let's play some video!

}

else

{

// no native video support available :(

}

Page 22: Learn html5

[email protected]

<header>

<footer>

<nav>

<nav>

Page 23: Learn html5

[email protected]

HEADER:

<header>

<h1>Heading Text</h1>

<p> Text or images can be included here</p>

<p> Logos are frequently placed here too</p>

</header>

The <header> tag can also contain an <hgroup> tag, as shown. The <hgroup> tag

groups headings together, using the <h1> to <h6> heading levels

shown here with a main heading and a sub-heading. <header> <hgroup> <h1>Main Heading</h1> <h2>Sub-heading </h2> </hgroup> <p> Text or images can be included here</p> </header>

Page 24: Learn html5

[email protected]

FOOTER:

The <footer> element contains information about a page, article, or section, such as

the author or date of the article.

As a page footer, it may contain copyright or other important legal information.

<footer>

<p>Copyright 2011 Acme United. All rights reserved.</p>

</footer>

The HTML5 specification says: ―A footer typically contains information about its

section such as

who wrote it, links to related documents, copyright data, and the like.‖

------------------------------------------------------------------------------------------------------------------

The Navigation area

<nav>

<ul>

<li><a href="#">Home</a></li>

<li><a href="#">About Us</a></li>

<li><a href="#">Our Products</a></li>

<li><a href="#">Contact Us</a></li>

</ul>

</nav>

Page 25: Learn html5

[email protected]

<menu> <nav>

<article>

<section> <section>

Page 26: Learn html5

[email protected]

<menu>

<button type="button" >Clio</button>

<button type="button" >Thalia</button>

<button type="button">Urania</button>

<button type="button">Calliope</button>

</menu>

------------------------------------------------------------------------------------------------------------------ <section>

The <section> element is commonly misused. Most people would think of using the

section tag as a container block level element to contain a portion of the site. This is

incorrect.

The true way to use the section element is to think of it in terms of grouping specific

portions of content. Inside a section you may have multiple headings to further narrow

the focus of the section and there may be multiple sections inside a particular piece of

content.

Page 27: Learn html5

[email protected]

The <section> tag—and the <article> tag, as well—can contain headers, footers, or

any other components required to complete the section. The <section> tag is for

grouping content. The content for both the <section> tag and the <article> tag usually

starts with a <header> and ends with a <footer>, with the content for the tag in

between.

The <section> tag can also contain <article> tags, just as the <article> tag can contain

the <section> tag

------------------------------------------------------------------------------------------------------------------

<article>

<section> Content </section>

<section> Content </section>

</article>

------------------------------------------------------------------------------------------------------------------

<section>

<article> Content </article>

<article> Content </article>

</section>

Page 28: Learn html5

[email protected]

<aside>

<figure>

<figure> <figcaption><figure>

<figure>

<img src="koala.jpg" width="304" height="228"> <figcaption>Caption for the figure</figcaption>

</figure>

Page 29: Learn html5

[email protected]

<aside>

Think of this tag as holding supplementary content that is not part of the flow of the

article it supplements. In magazines, asides are frequently used to highlight a point

that was made in the article itself. The <aside> tag contains content that can be

removed without affecting the information conveyed by the article, section, or page

that contains it.

<p>My family and I visited Euro Disney last year.</p>

<aside>

<h4>Disney in France</h4>

<p>Besides Euro Disney, there is a Disneyland in California.</p>

</aside>

Page 30: Learn html5

[email protected]

A Form of Madness

Page 31: Learn html5

[email protected]

<form>

Page 32: Learn html5

[email protected]

• Input type= datetime global date-and-time input control

• input type = datetime-local local date-and-time input control

• input type = date date input control

• input type = month year-and-month input control

• input type = time time input control

• input type = week year-and-week input control

• input type = number number input control

• input type = range imprecise number-input control

• input type = email e-mail address input control

• input type = url URL input control

• input type = search search field

• input type = tel telephone-number-input field

• input type = color color-well control

Page 33: Learn html5

[email protected]

Dojo jQuery UI YUI.

date, month, week, time, date + time, and

date+time–timezone.

• See Demos

Page 34: Learn html5

[email protected]

How to solve the problem for browsers that doesn’t support new input types

Ex

<form>

<input type="date" id="idate">

</form>

...

<script>

var idate = document.getElementById("idate");

if (idate.type != "date")

{

$("#idate").datepicker(); // using jQuery UI

}

</script>

Page 35: Learn html5

[email protected]

Input type Browsers

type="date"

type="month"

type="week"

type="time"

type="datetime"

type="datetime-local"

Page 36: Learn html5

[email protected]

<input type="number" min="0" max="10" step="2" value="6"/>

type

min

max

step

value

Page 37: Learn html5

[email protected]

• Input.stepUp(n)

• input.stepDown(n)

• input.valueAsNumber

input.value

Page 38: Learn html5

[email protected]

if (!Modernizr.inputtypes.number) {

// no native support for type="number" fields

// maybe try Dojo or some other JavaScript framework

}

Page 39: Learn html5

[email protected]

<input type="range" min="0" max="10" step="2" value="6"/>

Page 40: Learn html5

[email protected]

The latest versions of Safari, Chrome, and Opera all do this.

(Sadly, the iPhone renders it as a simple text box. It doesn’t even optimize its

onscreen keyboard for numeric input.)

All other browsers simply treat the field as type="text"

Page 41: Learn html5

[email protected]

• <input type="email">

setCustomValidity().

• object.setCustomValidity("WRONG!!");

Page 42: Learn html5

[email protected]

The email INPUT tag gives you a way to request email addresses in your web form.

In most web browsers, this won't look any different than a standard .

Where this field becomes important is on mobile devices that change their interface

for email address fields, such as the iPhone, iPad, and iPod.

On those devices, email form fields are given a different keyboard with things like

readily available @-key, period, and minimized spacebar.

Page 43: Learn html5

[email protected]

• <input type="url">

Page 44: Learn html5

[email protected]

• <input type="search">

• <input type="tel">

Page 45: Learn html5

[email protected]

• <input type="color">

Page 46: Learn html5

[email protected]

New form attributes and functions

Page 47: Learn html5

[email protected]

placeholder

text,

search, url, tel, email password

<input placeholder="First and last name" required/>

Page 48: Learn html5

[email protected]

autocomplete

<input type="text" name="creditcard" autocomplete="off">

Page 49: Learn html5

[email protected]

on

off

unspecified

Page 50: Learn html5

[email protected]

autofocus

autofocus

<input type="search" name="criteria" autofocus>

boolean

Page 51: Learn html5

[email protected]

list datalist

<datalist id="contactList">

<option value="[email protected]" label="Racer X">

<option value="[email protected]" label="Peter">

</datalist>

<input type="email" list="contactList">

Page 52: Learn html5

[email protected]

To use this combination: 1. Create a datalistelement in your document with its id set to a unique value.

The datalist can be located anywhere in the document.

2. Populate the datalist with as many option elements as needed to represent

the full set of suggestions for values of a control.

For example, a datalist representing e-mail contacts should contain all of the contact

e-mail addresses as individual option children.

<datalist id="contactList">

<option value="[email protected]" label="Racer X">

<option value="[email protected]" label="Peter">

</datalist>

3. Link the input element to the datalistby setting the listattribute to a value

which is the idof the associated datalist.

<input type="email" id="contacts" list="contactList">

Page 53: Learn html5

[email protected]

required

<input type="text" required>

Page 54: Learn html5

[email protected]

The valueMissing Constraint

Purpose: Ensure that some value is set on this form control

Usage: Set the requiredattribute on the form control to true

Usage example: <input type="text" name="myText" required> Details: If the required attribute is set on a form control, the control will be in an

invalid state unless the user or a programmatic call sets some value to the field.

For example, a blank text field will fail a required check, but will pass as soon as any

text is entered. When blank, the valueMissing will return true.

Page 55: Learn html5

[email protected]

<input type="text" pattern="[0-9]{16}">

Page 57: Learn html5

[email protected]

• <canvas>

<canvas>

Page 58: Learn html5

[email protected] [email protected]

What Is a Canvas?

When you use a canvas element in your web page, it creates a rectangular

area on the page.

By default, this rectangular area is 300 pixels wide and 150 pixels high, but

you can specify the exact size and set other attributes for your canvas

element.

Page 59: Learn html5

[email protected]

<canvas>

Page 60: Learn html5

[email protected]

<canvas id="myCanvas" width="200" height="100"></canvas>

Page 61: Learn html5

[email protected]

<canvas id="myCanvas" width="200" height="100">

Your Browser Doesn’t Support Canvas

</canvas>

Page 62: Learn html5

[email protected]

<canvas id="myCanvas" width="200" height="100"

style="border:1px solid #000000;">

</canvas>

Page 63: Learn html5

[email protected]

if (canvas.getContext)

{

...

}

else{ // put code for browsers that don't support canvas here}

OR

if (Modernizr.canvas) {. . .}

else{// put code for browsers that don't support canvas here}

Page 64: Learn html5

[email protected]

<head>

<!--[if IE]>

<script src="excanvas.js"></script>

<![endif]-->

</head>

Page 65: Learn html5

[email protected]

• <script type="text/javascript">

var c=document.getElementById("myCanvas");

var ctx=c.getContext("2d");

ctx.fillStyle="#FF0000";

ctx.fillRect(0,0,150,75);

</script>

Page 66: Learn html5

[email protected] [email protected]

To programmatically use a canvas, you have to first get its

context.

You can then perform actions on the context and finally apply

those actions to the context.

You can think of making canvas modifications as similar to

database transactions: you start a transaction, perform certain

actions, and then commit the transaction.

Page 67: Learn html5

[email protected]

getContext("2d")

Page 68: Learn html5

[email protected]

fillStyle

fillRect(x,y,width,height)

strokeStyle fillStyle —

• strokeRect(x,y,width,height)

Page 69: Learn html5

[email protected] [email protected]

EXAMPLE:

<script type="text/javascript">

function drawSquare () {

var canvas = document.getElementById('draw-square');

if (canvas.getContext) {

var context = canvas.getContext('2d');

context.fillStyle = "rgb(150,29,28)";

context.fillRect (2,2,96,96);

} else {

// put code for browsers that don't support canvas here

}

} </script>

Page 70: Learn html5

[email protected] [email protected]

The first thing this script does is find the element with the

id draw-square:

var canvas = document.getElementById('draw-square');

Then it checks to see if the browser supports the context

method on this element.

This is an easy way to make sure that your canvas will only

display on browsers that support the tag.

if (canvas.getContext) { ... }

Page 71: Learn html5

[email protected] [email protected]

The context is the rendering context that is used to manipulate

content that is displayed.

You should use a 2-dimensional (2d) rendering context. But in

the future, 3-dimensional context may be supported.

Once I have the context, I need to build my square with the two

lines:

context.fillStyle = "rgb(150,29,28)";

context.fillRect (2,2,96,96);

I created a square that is red (rgb(150,29,28)) and is positioned

2 pixels down and 2 pixels over and 96 pixels wide and high

(fillRect (2,2,96,96)).

Then, in the else section of my script, I can put any JavaScript I

want to display if the canvas element isn’t supported.

Page 72: Learn html5

[email protected]

• fillRect(x,y,width,height):

strokeRect(x,y,width,height):

clearRect(x,y,width,height):

Page 73: Learn html5

[email protected]

fillRect()

Page 74: Learn html5

[email protected] [email protected]

Like other 2d platforms, it uses a flat Cartesian coordinate

system with the origin (0, 0) at the top left.

Moving to the right will increase the x value, and moving

downwards will increase the y value.

Understanding how the coordinate system works is integral if

you want to have things draw in the right place.

A single unit in the coordinate system is usually equivalent to 1

pixel on the screen, so the position (24, 30) would be 24 pixels

right and 30 pixels down.

Page 75: Learn html5

[email protected]

• moveTo(x,y)

• lineTo(x,y)

stroke().

• closePath():

• lineWidth = 4:

• context.lineJoin='round‘ :

Page 76: Learn html5

[email protected]

• quadraticCurveTo(x1,y1, x2,y2):

Page 77: Learn html5

[email protected]

X2,Y2 X1,Y1

Page 78: Learn html5

[email protected]

• drawImage(image, dx, dy)

(dx, dy)

(0,0)

• drawImage(image, dx, dy, dw, dh)

dw dh

(dx, dy).

Page 79: Learn html5

[email protected]

• drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh)

(sx, sy, sw, sh),

(dw, dh), (dx,

dy).

<img> Image

Page 80: Learn html5

[email protected]

• createLinearGradient(x0,y0,x1,y1)

(x0,y0) (x1,y1).

Page 81: Learn html5

[email protected]

• createRadialGradient(x0,y0,r0,x1,y1,r1)

(x0,y0) r0.

(x1,y1) r1.

Page 82: Learn html5

[email protected]

addColorStop

Page 83: Learn html5

[email protected]

<canvas id="d" width="300" height="225"></canvas>

<script>

var d_canvas = document.getElementById("d");

var context = d_canvas.getContext("2d");

var my_gradient = context.createLinearGradient(0,0,300,0);

my_gradient.addColorStop(0, "black");

my_gradient.addColorStop(1, "white");

context.fillStyle = my_gradient;

context.fillRect(0, 0, 300, 225);

</script>

Page 84: Learn html5

[email protected]

var bg= new Image();

bg= "gravel.jpg";

bg.onload = function (){

.....

context.strokeStyle=context.createPattern(bg,'repeat')

.....

}

Page 85: Learn html5

[email protected] [email protected]

As you can see, we are still calling stroke() for our path.

However, this time we have set a strokeStyle property on the

context first, passing in the result of a call to context.createPattern. and once again the image needs

to be previously loaded in order for the canvas to perform the

operation.

The second argument is a repetition pattern that can be one of

the choices :

repeat (Default) The image is repeated in both directions

repeat-x The image is repeated only in the X dimension

repeat-y The image is repeated only in the Y dimension

no-repeat The image is displayed once and not repeated

Page 87: Learn html5

[email protected]

scale(x,y)

Page 88: Learn html5

[email protected]

context.rotate(angle)

context.save();

// rotation angle is specified in radians

context.rotate(1.57);

context.drawImage(myImage, 0, 0, 100, 100);

context.restore();

Page 89: Learn html5

[email protected]

• fillText (text, x, y, maxwidth)

• strokeText (text, x, y, maxwidth)

Page 90: Learn html5

[email protected] [email protected]

Both functions take the text as well as the location at which it

should be drawn.

Optionally, a maxwidth argument can be provided to constrain

the size of the text by automatically shrinking the font to fit the

given size.

Page 91: Learn html5

[email protected]

• font

• textAlign

text-align

start, end, left, right, center.

• textBaseline

top, hanging, middle, alphabetic,

ideographic, and bottom.

Page 92: Learn html5

[email protected]

• textBaseline

Page 93: Learn html5

[email protected] [email protected]

The top of the em square is roughly at the top of the glyphs in a

font, the hanging baseline is where some glyphs like ը are

anchored, the middle is half-way between the top of the

em square and the bottom of the em square, the alphabetic

baseline is where characters like Á, ÿ, f, and Ω are anchored,

the ideographic baseline is where glyphs like 私 and

達 are anchored

and the bottom of the em square is roughly at the bottom of the

glyphsin a font.

The top and bottom of the bounding box can be far from these

baselines, due

to glyphs extending far outside the em square

Page 94: Learn html5

[email protected]

context

• shadowColor

• shadowOffsetX:

• shadowOffsetY:

• shadowBlur

Page 95: Learn html5

[email protected]

requestAnimFrame

Page 96: Learn html5

[email protected]

window.requestAnimFrame = (function(callback) {

return window.requestAnimationFrame || window.webkitRequestAnimationFrame ||

window.mozRequestAnimationFrame ||

window.oRequestAnimationFrame ||

window.msRequestAnimationFrame ||

function(callback) {

window.setTimeout(callback, 1000 / 60);

};

})(); // call function after its declaration

Page 97: Learn html5

[email protected]

function animate() {

// get canvas and its context

.....

// clear canvas context

context.clearRect(0, 0, canvas.width, canvas.height);

// draw stuff

.....

// request new frame

requestAnimFrame(function() {

animate();

});

}// end of animate function

Page 98: Learn html5

[email protected]

SVG

Vector-based graphics for the Web

Page 100: Learn html5

[email protected]

<svg viewBox="0 0 320 240“ style=“border: 1px solid #999; width: 320px; height:240px;">

</svg>

Page 101: Learn html5

[email protected]

<svg id="mysvg" viewBox="0 0 320 240" style="border: 1px solid #999; width: 320px; height:240px;">

<rect x="50" y="50" width="100" height="100“ style="fill: rgb(255,0,0)">

</rect>

<line x1="50" y1="50" x2="150" y2="150"

style="stroke: rgb(0,127,127); stroke-width: 5;">

</line>

<circle cx="165" cy="100" r="50"

style="fill:rgb(0,255,0);">

</circle>

</svg>

Page 102: Learn html5

[email protected]

<polygon points="265,50 315,150 215,150"

style="stroke: rgb(51,51,51); fill: rgb(204,204,204);

stroke-width: 5;">

</polygon>

Page 103: Learn html5

[email protected]

<polyline>

Page 104: Learn html5

[email protected]

<rect x="50" y="50" width="100" height="100"

fill="rgb(255,0,0)"></rect>

<line x1="50" y1="50" x2="150" y2="150"

stroke="rgb(0,127,127)" stroke-width="5"></line>

Page 105: Learn html5

[email protected]

rect {

fill: rgb(255,0,0);

}

line {

stroke: rgb(0,127,127);

stroke-width: 5;

}

Page 106: Learn html5

[email protected]

<image x="10" y="10"

width="236" height="260"

xlink:href="example.png">

</image>

xlink:href

Page 107: Learn html5

[email protected]

<text x="10" y="20">

Hi everybody , everything is OK!

</text>

Page 109: Learn html5

[email protected]

No Plugin?? -- Yes -- no plugin

Page 110: Learn html5

[email protected]

<audio>

– The <audio> tag identifies sound content, such as music or any other audio

streams.

– The <audio> tag has attributes that control what, when, and how audio will be played. The attributes are src, preload, controls, loop, and autoplay.

<audio src="MyFirstMusic.ogg" controls autoplay loop>

Your browser does not support the audio tag.

</audio>

Page 111: Learn html5

[email protected]

<source>

<source>

– The <video> and <audio> tags can contain the <source> tag, which

defines multimedia resources for <video> and <audio>tags.

– With this element, you specify alternative video and audio files from

which the browser can then choose based on its media type or codec

support.

<audio controls>

<source src="MyFirstAudio.ogg" />

<source src=" MyFirstAudio.mp3" />

<p>Your browser does not support the audio tag</p>

</audio>

Page 112: Learn html5

[email protected]

Browser MP3 Wav Ogg

Internet Explorer 9 YES NO NO

Firefox 4.0 NO YES YES

Google Chrome 6 YES YES YES

Apple Safari 5 YES YES NO

Opera 10.6 NO YES YES

<audio>

Page 114: Learn html5

[email protected]

1. load():

2. play():

3. pause():

4. canPlayType(type):

Page 115: Learn html5

[email protected]

1. Duration :

2. Paused:

3. ended

4. startTime

5. error

6. currentSrc :

Page 116: Learn html5

[email protected]

1. autoplay :

2. loop

3. currentTime

4. controls

5. volume

6. muted

Page 117: Learn html5

[email protected]

Problems, Problems, and Solutions

Page 119: Learn html5

[email protected]

<embed>

<embed>

<embed src="intro.swf" height="200" width="200">

• Problems:

Page 120: Learn html5

[email protected]

<object>

<object>

<object data="intro.swf" height="200" width="200">

• Problems:

Page 121: Learn html5

[email protected]

<video> <video>

– allows you to broadcast video clips or streaming visual media.

– It has all the attributes of the <audio> tag plus three more: poster, width,

and height.

– The poster attribute lets you identify an image to be used while the video is

loading or in the case when the video won't load at all.

<video src="MyFirstMovie.ogg" controls="controls">

Your browser does not support the video tag

</video>

• Problems:

<video>

Page 122: Learn html5

[email protected]

<video>

<video width="320" height="240" controls> <source src="movie.mp4" type="video/mp4"> <source src="movie.ogg" type="video/ogg"> <source src="movie.webm" type="video/webm"> <object data="movie.mp4" width="320" height="240"> <embed src="movie.swf" width="320" height="240"> </object> </video>

Page 123: Learn html5

[email protected]

1. poster :

2. width, height

3. videoWidth, videoHeight

Page 124: Learn html5

[email protected]

You Are Here (And So Is Everybody Else)

Page 127: Learn html5

[email protected]

navigator

navigator.geolocation

function get_location() {

navigator.geolocation.getCurrentPosition(show_map);

}

if (Modernizr.geolocation)

Page 128: Learn html5

[email protected]

getCurrentPosition()

Page 129: Learn html5

[email protected]

show_map()

getCurrentPosition()

getCurrentPosition(callback function)

Page 130: Learn html5

[email protected]

function show_map(position) {

var latitude = position.coords.latitude;

var longitude = position.coords.longitude;

// let's show a map or do something interesting!

}

coords timestamp

getCurrentPosition(callback function)

Page 131: Learn html5

[email protected]

(Since this is all happening asynchronously, you can’t really

know when that will happen in advance.

It might take some time for the user to read the info bar and agree to share

her location, devices with dedicated GPS hardware may take some more

time to connect to a GPS satellite, and so on.)

Page 132: Learn html5

[email protected]

position.coords

position.coords

Property Type Notes

coords.latitude double Decimal degrees

coords.longitude double Decimal degrees

coords.altitude doubleor null Meters above the reference ellipsoid

coords.accuracy double Meters

coords.altitudeAccuracy doubleor null Meters

coords.heading doubleor null Degrees clockwise from true north

coords.speed doubleor null Meters/second

Page 133: Learn html5

[email protected]

Only three of the properties are guaranteed to be there (coords.latitude,

coords.longitude, and coords.accuracy).

The rest might come back as null, depending on the capabilities of your

device and the backend positioning server with which it communicates.

The headingand speedproperties are calculated based on the user’s

previous position, if possible.

Page 134: Learn html5

[email protected]

getCurrentPosition()

navigator.geolocation.getCurrentPosition(

show_map, handle_error).

PositionError

code message

Page 135: Learn html5

[email protected]

code

Page 136: Learn html5

[email protected]

function handle_error(err) {

if (err.code== 1) {

// user said no!

}

}

Page 137: Learn html5

[email protected]

getCurrentPosition()

PositionOptions

PositionOptions

• enableHighAccuracy

• timeout

• maximumAge

Page 138: Learn html5

[email protected]

Ex: navigator.geolocation.getCurrentPosition(

success_callback, error_callback, {maximumAge: 75000});

What you’re saying is that you don’t necessarily need the user’s

currentlocation.

You would be satisfied with knowing where he was 75 seconds (75000

milliseconds) ago.

Page 139: Learn html5

[email protected]

watchPosition()

getCurrentPosition().

Page 140: Learn html5

[email protected]

watchPosition()

clearWatch(t)

setInterval() clearInterval()

Page 141: Learn html5

[email protected]

geolocation

<script

src=" http://maps.google.com/maps/api/js?sensor=false">

</script>

var map = new

google.maps.Map(document.getElementById("map_div"), myOptions);

//the div to display on , and options for map

Page 142: Learn html5

[email protected]

var myOptions = {

zoom: 8, //the zoom level 0 to 21

center: new google.maps.LatLng(latitude, longitude),

//the center of map displayed

mapTypeId: google.maps.MapTypeId.ROADMAP

//Map Type

}

Page 145: Learn html5

[email protected]

– sessionStorage localStorage

window

Page 146: Learn html5

[email protected]

window.sessionStorage.setItem(‘myFirstKey’, ‘myFirstValue’);

myFirstValue myFirstKey

Page 147: Learn html5

[email protected]

getItem

alert(window.sessionStorage.getItem(‘myFirstKey’));

window.sessionStorage.myFirstKey = ‘myFirstValue’;

alert(window.sessionStorage.myFirstKey);

Page 148: Learn html5

[email protected]

localStorage

Page 149: Learn html5

[email protected]

sessionStorage localStorage

Values persist only as long as

the window or tab in which

they were stored

Values persist beyond window and

browser lifetimes.

Values are only visible within

the window or tab that created

them.

Values are shared across every window

or tab

running at the same origin.

Page 150: Learn html5

[email protected]

length

key(index)

• getItem(key)

null

Page 151: Learn html5

[email protected]

• setItem(key, value)

QUOTA_EXCEEDED_ERR

Page 152: Learn html5

[email protected]

• removeItem(key) :

Page 153: Learn html5

[email protected]

Threads in JS

Page 155: Learn html5

[email protected]

worker = new Worker("myWorker.js");

Page 156: Learn html5

[email protected]

postMessage

postMessage()

.

worker.postMessage("a message from parent page");

Page 157: Learn html5

[email protected]

postMessage()

onmessage

event.data

onmessage = function myFunction(event)

{

event.data;

……

postMessage('a message to the parent page');

}

myWorkers.js

Page 158: Learn html5

[email protected]

ErrorEvent

Worker.onerror = function(e)

{…………}