10953A HTML5 Programming Companion Content
10953A HTML5 Programming Companion Content
10953A
HTML5 Programming
Companion Content
2 HTML5 Programming
Information in this document, including URL and other Internet Web site references, is subject to change
without notice. Unless otherwise noted, the example companies, organizations, products, domain names,
e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with
any real company, organization, product, domain name, e-mail address, logo, person, place or event is
intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the
user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in
or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical,
photocopying, recording, or otherwise), or for any purpose, without the express written permission of
Microsoft Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property
rights covering subject matter in this document. Except as expressly provided in any written license
agreement from Microsoft, the furnishing of this document does not give you any license to these
patents, trademarks, copyrights, or other intellectual property.
The names of manufacturers, products, or URLs are provided for informational purposes only and
Microsoft makes no representations and warranties, either expressed, implied, or statutory, regarding
these manufacturers or the use of the products with any Microsoft technologies. The inclusion of a
manufacturer or product does not imply endorsement of Microsoft of the manufacturer or product. Links
may be provided to third party sites. Such sites are not under the control of Microsoft and Microsoft is not
responsible for the contents of any linked site or any link contained in a linked site, or any changes or
updates to such sites. Microsoft is not responsible for webcasting or any other form of transmission
received from any linked site. Microsoft is providing these links to you only as a convenience, and the
inclusion of any link does not imply endorsement of Microsoft of the site or the products contained
therein.
© 2012 Microsoft Corporation. All rights reserved.
Microsoft, and Windows are either registered trademarks or trademarks of Microsoft Corporation in the
United States and/or other countries.
All other trademarks are property of their respective owners.
Released: 04/2012
HTML5 Programming 3
4 HTML5 Programming
HTML5 Programming 5
6 HTML5 Programming
HTML5 Programming 7
Module 1
Introduction to HTML5 Development
Contents:
Lesson 1: Overview of HTML 8
Lesson 1
Overview of HTML
Contents:
Detailed Demonstration Steps 9
Additional Reading 11
HTML5 Programming 9
2. Open a Notepad.exe (On the Windows Start menu, click Run, type notepad and then click OK).
<!DOCTYPE html>
<!DOCTYPE html>
<html>
</html>
5. Create the head and body elements inside the HTML element.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
6. Add a title to the head element and some content to the body element.
<!DOCTYPE html>
<html>
<head>
<title>Your first HTML document</title>
</head>
<body>
<p>Hello HTML!</p>
</body>
</html>
8. Run the saved file by double-clicking it, and show the students the completed webpage.
<div>This is a division.</div>
<div> This is another division</div>
<span>This is a span</span>
<span>This is another span</span>
<p>This is a paragraph</p>
<a href="http://www.microsoft.com">A link to Microsoft site</a>
<table border="1">
<tr>
<th>header 1</th>
<th>header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
<ul>
<li>item1</li>
<li>item2</li>
</ul>
7. Run the saved file and show the students the completed webpage.
7. Run the saved file and show the students the completed webpage.
HTML5 Programming 11
Additional Reading
The HTML Document
• Languages
• Encoding
12 HTML5 Programming
Lesson 2
What’s New in HTML5?
Contents:
Detailed Demonstration Steps 13
HTML5 Programming 13
3. In the HTML file, add the following HTML content to the body element:
<h1>The Header</h1>
<div id="content">The Content</div>
<div class="footer">The Footer</div>
4. In the HTML file, add a style element inside the head element before the head element’s closing tag.
<style type="text/css">
h1
{
font-family: Arial sans-serif;
font-size: 36px;
text-decoration: underline;
color: brown;
text-align: center;
}
#content
{
background-color: brown;
color: white;
font-weight: bold;
height: 200px;
}
.footer
{
font-size: 0.6em;
color: gray;
text-align: right;
}
</style>
6. Run the saved file and show the students the completed webpage.
14 HTML5 Programming
Lesson 3
Introduction to JavaScript
Contents:
Detailed Demonstration Steps 15
HTML5 Programming 15
3. If the developer tools opens in a separate window, instead of in a pane at the lowermost part of the
browser window, click the Pin button at the upper-right part of the window.
alert("Hello");
7. Enter the following line of code to print the type string of a number.
typeof 42;
9. Enter the following line to declare and assign a new variable called message.
10. Enter the following line to display the value of the message variable.
message;
12. Enter the following line to show the value of the variable in an alert.
alert(message);
<h1>The Header</h1>
<div id="content">The Content</div>
4. In the HTML file, add a script element inside the head element before the head element’s closing
tag.
16 HTML5 Programming
<script type="text/javascript">
function contentLoaded() {
var content = document.getElementById("content");
content.textContent = "This content was modified using JavaScript.";
}
6. Run the saved file and show the students the completed webpage containing the text modified using
JavaScript.
HTML5 Programming 17
Lesson 4
Introduction to jQuery
Contents:
Detailed Demonstration Steps 18
18 HTML5 Programming
2. In Visual Studio 2010, create a new ASP.NET Empty Web Application called HellojQuery.
6. In the HTML file, add the following script tags inside the head element.
<head>
<title>Hello jQuery</title>
<script src="jquery-1.5.1.js"></script>
<script src="HellojQuery.js"></script>
</head>
7. Drag the vsdoc file into the surface of the opened HellojQuery.js file to create the statement and
inform the students that you have added IntelliSense for jQuery by doing that.
8. Add the following code in the HellojQuery.js file to demonstrate the wiring of the ready event.
$(document).ready(function() {
alert("Hello jQuery ready function");
});
<div id="main">
</div>
<ul id="ulOfItems">
<li>item 1</li>
<li class="red">item 2</li>
<li id="item3">item 3</li>
</ul>
<br />
HTML5 Programming 19
<div>Hello jQuery</div>
<div id="result"></div>
This creates the page markup containing an unordered list and two divs.
var resultDiv;
$(document).ready(function () {
resultDiv = $("#result");
$("li").each(function () {
resultDiv.text(resultDiv.text() + " " + this.tagName);
});
$("#item3").each(function () {
resultDiv.text(resultDiv.text() + " " + this.id);
});
$(".red").each(function () {
resultDiv.text(resultDiv.text() + " " + this.tagName);
});
$("ul#ulOfItems").each(function () {
resultDiv.text(resultDiv.text() + " " + this.id);
});
});
Write to the result div, all tag names of the selected list items, the id of the selected item3, the tag name li
once for the list item with the red class name, and the id of the unordered list, ulOfItems, retrieved by the
precise selector.
4. Add the following JavaScript code in the HellojQuery.js file inside the ready handler:.
$("#btnEach").click(function () {
$("div").each(function (i) {
alert(i + "=" + $(this).text());
});
});
The code wires a click event to the input with the button type. When the button is clicked, an alert is
shown for each div in the page with the div index and the div text.
<p></p>
<input type="button" id="btnCreateParagraph" value="Create Paragraph Data" /><br
/>
<input type="button" id="btnAppendToUl" value="Append Two List Items Using
appendTo" />
8. Add the following JavaScript code in the HellojQuery.js file inside the ready handler:.
$("#btnCreateParagraph").click(function () {
$("p").html("<div>Hello jQuery!</div>");
});
$("#btnAppendToUl").click(function () {
$("<li />").html("last").appendTo("ul");
$("<li />").html("new first").prependTo("ul");
});
The code wires two click event handlers to the buttons. The first handler adds a new div element with the
“Hello jQuery!” text to the paragraph element. The second event handler creates two list items that are
added as the first and last list items in the unordered list in the HTML.
Module 2
Creating Page Structure and Navigation
Contents:
Lesson 1: HTML5 Structural Elements 22
Lesson 1
HTML5 Structural Elements
Contents:
Detailed Demonstration Steps 23
Additional Reading 26
HTML5 Programming 23
<body>
<header>
<h1>Page Title</h1>
<nav>
<ul>
<li>navigation 1</li>
<li>navigation 1</li>
</ul>
</nav>
</header>
<section>
<article>
<h2>Article Title</h2>
<p>Article content</p>
</article>
</section>
<footer>
<p>Copyright 2011 Microsoft</p>
</footer>
</body>
<body>
This is<mark>marked</mark> text <p>Your test score in the test was <meter
value="70" min="0" max="100" low="54" high="100" optimum="100">70</meter></p>
<p>Downloaded: <progress value="16" max="48">33%</progress> of the content</p>
<p>Output: <input type="text" value="1" /> + <input type="text" value="3" /> =
<output>4</output></p>
<p>The time is now: <time>2011-11-12T14:54Z</time></p>
</body>
5. Run the saved file and show the students the completed web page
24 HTML5 Programming
<body>
<header>
<h1>
Something Important Happened Somewhere</h1>
<nav>
<!-- Site Navigation -->
<ul>
<li><a href="/">Home</a></li>
<li><a href="/entertainment">Entertainment</a></li>
<li><a href="/politics">Politics</a></li>
<li><a href="/sports">Sports</a></li>
</ul>
</nav>
</header>
<article>
<header>
<p>
Table of Contents</p>
<nav>
<ul>
<li><a href="#summary">Summary</a></li>
<li><a href="#details">The Details</a></li>
<li><a href="#sources">Sources</a></li>
</ul>
</nav>
</header>
<section>
<header>
<h2>
Somebody did Something Vital Yesterday</h2>
</header>
<p>
This is the summary of the article.</p>
</section>
<section>
The main content of the article would be here.
</section>
<section>
<header>
<h2>
Sources</h2>
</header>
<ul>
<!-- a link menu that is not wrapped in a nav element -->
<li><a href="http://www.example.com/link1">A Well Known
Source</a></li>
</ul>
</section>
</article>
</body>
5. Run the saved file and show the students the completed web page
26 HTML5 Programming
Additional Reading
Other New Elements
• HTML5 Specifications
HTML5 Programming 27
Lesson 2
Navigation and Menus
Contents:
Detailed Demonstration Steps 28
28 HTML5 Programming
<body>
<header>
<h1>
Something Important Happened Somewhere</h1>
<nav>
<!-- Site Navigation -->
<ul>
<li><a href="/">Home</a></li>
<li><a href="/entertainment">Entertainment</a></li>
<li><a href="/politics">Politics</a></li>
<li><a href="/sports">Sports</a></li>
</ul>
</nav>
</header>
<article>
<header>
<p>
Table of Contents</p>
<nav>
<ul>
<li><a href="#summary">Summary</a></li>
<li><a href="#details">The Details</a></li>
<li><a href="#sources">Sources</a></li>
</ul>
</nav>
</header>
<section>
<header>
<h2>
Somebody did Something Vital Yesterday</h2>
</header>
<p>
This is the summary of the article.</p>
</section>
<section>
The main content of the article would be here.
</section>
<section>
<header>
<h2>
Sources</h2>
</header>
<ul>
<!-- a link menu that is not wrapped in a nav element -->
<li><a href="http://www.example.com/link1">A Well Known
Source</a></li>
</ul>
</section>
</article>
</body>
HTML5 Programming 29
5. Run the saved file and show the students the completed web page
30 HTML5 Programming
• Better accessibility
• Better searchability
• Better interoperability
Tools
Visual Studio 2010
HTML5 Programming 31
Module 3
Creating Form Input and Validation
Contents:
Lesson 1: Working with Input Types 32
Lesson 3: Validation 37
Lesson 1
Working with Input Types
Contents:
Detailed Demonstration Steps 33
HTML5 Programming 33
<body>
<form>
<label for="dpBirthDate">Date: </label><input type="date" name="dpBirthDate"
value="2011-12-19" /><br/>
<label for="dpCCExpiration">Month: </label><input type="month"
name="dpCCExpiration" value="2011-12" /><br/>
<label for="dpArrivalWeek">Week: </label><input type="week"
name="dpArrivalWeek" value="2011-W16" /><br/>
<label for="dpDepartureTime">Time: </label><input type="time"
name="dpDepartureTime" value="17:39:57" /><br/>
<label for="dpBirthDate">Datetime: </label><input type="datetime"
name="dpBirthDate" value="2011-12-31T23:59:60Z" /><br/>
<label for="dpBirthDate">Datetime-local: </label><input type="datetime-local"
name="dpBirthDate" value="2011-12-19T16:39:57" /><br/>
</form>
</body>
5. Run the saved file and show the students the completed web page
3. Run the saved file and show the students the completed web page
3. Run the saved file and show the students the completed web page
HTML5 Programming 35
Lesson 2
Using Form Attributes
Contents:
Detailed Demonstration Steps 36
36 HTML5 Programming
<body>
<form>
<input type="text" placeholder="Enter your full name" name="FullName"
autofocus="autofocus" autocomplete="on" />
<input type="password" placeholder="Type your password" name="Password" />
<input type="number" placeholder="Enter your age" name="Age" />
<input type="text" name="country" list="countries" />
<datalist id="countries">
<option value="Canada" />
<option value="England" />
<option value="France" />
<option value="Germany" />
<option value="Japan" />
<option value="Russia" />
<option value="United States" />
</datalist>
<input type="file" name="photos" multiple="multiple" />
</form>
Lesson 3
Validation
Contents:
Detailed Demonstration Steps 38
38 HTML5 Programming
<body>
<form>
<input type="text" name="username" required="required" />
<label> Zip Code: <input type="text" pattern="\d{5}" name=”zip” /></label>
<input type="text" name="address" maxlength="10" />
<input type="submit" name="submit" value="Submit The Form" />
</form>
</body>
Lesson 4
Using Browser Detection, Feature Detection, and
Modernizr
Contents:
Question and Answers 40
Additional Reading 42
40 HTML5 Programming
Answer: Feature detection makes no assumptions. Using this technique will reveal whether a
feature exists. On the other hand, browser detection makes the assumption that you
succeeded in detecting the browser, although knowing the browser does not always mean
that you know the value of each feature.
Answer: Polyfills help to introduce HTML5 features or elements to browsers that do not
support them. This helps to create the same behavior, markup, and user experience across
most of the browsers.
HTML5 Programming 41
4. In the html file add the following script tag inside the head element:
<head>
<title>Hello Modernizr</title>
<script src="modernizr-1.7.js"></script>
</head>
<body>
<script type=”text/javascript”></script>
</body>
if (Modernizr.canvas)
{
alert(‘canvas is available’);
}
if (Modernizr.video)
{
alert(‘video is available’);
}
if (Modernizr.audio)
{
alert(‘audio is available’);
}
Additional Reading
Browser Detection
• Conditional Comments
HTML5 Programming 43
Answer: There are many strategies to apply HTML5 features today. One strategy is feature
detection (and in particular, the Modernizr JavaScript library), which enables you to detect
features, and reacts if these do not exist in the browser. You can also use polyfills to meet
your requirements.
44 HTML5 Programming
Module 4
Laying Out and Styling Webpages
Contents:
Lesson 1: Creating Layouts 45
Lesson 1
Creating Layouts
Contents:
Detailed Demonstration Steps 46
Additional Reading 47
46 HTML5 Programming
<body>
<div>
<header><h1>Page Title</h1></header>
<div>
<menu style=" width:200px;float:left;"> Menu</menu>
<section style="width:400px;float:left;">Page Content</section>
</div>
<footer style="clear:both;">Footer</footer>
</div>
</body>
5. Run the saved file and show the students the completed webpage.
HTML5 Programming 47
Additional Reading
Using CSS3 for Layout
• CSS3 Template Layout
• CSS3 Multi-Coulmn
48 HTML5 Programming
Lesson 2
Advanced CSS by Using CSS3
Contents:
Detailed Demonstration Steps 49
Additional Reading 51
HTML5 Programming 49
<div id="element"></div>
4. In the HTML file’s head element add the following style tag:
<style type="text/css">
#element
{
position: absolute;
left: 50px;
top: 50px;
height: 20px;
width: 20px;
background-color: Red;
-ms-transform: rotate(30deg) scale(1.5, 2);
}
</style>
6. Run the saved file and show the students the completed web page
<div id="element">This element has a border. When the screen’s width is less than
400 pixels the border is removed</div>
4. In the HTML file’s head element add the following style tag:
<style type="text/css">
#element
{
border: solid 1px black;
}
@media screen and (max-width:400px)
{
#element
{
border: none;
}
50 HTML5 Programming
}
</style>
6. Run the saved file and show the students the completed web page.
7. Change the screen’s width to show the students the media query effect
HTML5 Programming 51
Additional Reading
Selectors
• CSS3 Selectors
Animations
• CSS3 Animations
Media Queries
• CSS3 Media Queries
52 HTML5 Programming
Answer: The basic considerations include aspects such as space and white space, using
images and graphics, working with text width, and element placement and position.
HTML5 Programming 53
Module 5
Getting Started with Graphics and Multimedia Elements
Contents:
Lesson 1: Canvas Basics 54
Lesson 1
Canvas Basics
Contents:
Detailed Demonstration Steps 55
HTML5 Programming 55
3. In the HTML file, add a canvas element with fallback content inside the body element.
<canvas id="canvas">
<div>Your browser does not support the canvas element.</div>
</canvas>
4. In the HTML file, add a style element inside the head element before the head element’s closing tag.
<style type="text/css">
canvas { border: solid 1px green; }
div { background-color: orange; }
</style>
<canvas id="canvas">
</canvas>
4. In the HTML file, add a script element inside the head element before the head element’s closing
tag.
<head>
...
<script type="text/javascript">
</script>
</head>
5. Inside the script element, call the new draw function after the page finishes loading, and retrieve the
canvas context before starting to draw.
<script type="text/javascript">
function draw() {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
}
</script>
6. At the end of the draw function, add the following code to draw a filled rectangle.
function draw() {
...
var context = canvas.getContext("2d");
8. Run the saved file and show the students the filled rectangle drawn on the canvas.
9. At the end of the draw function, add the following code to draw the circumference of a circle.
function draw() {
...
11. Run the saved file and show the students the circle drawn on the canvas.
12. At the end of the draw function, add the following code to draw part of a rectangle inside a clipping
region defined by a circle.
function draw() {
...
context.beginPath();
context.moveTo(260, 75);
context.arc(230, 75, 30, 0, 2 * Math.PI, true);
context.clip();
context.beginPath();
context.rect(180, 55, 100, 40);
context.fill();
}
14. Run the saved file and show the students the partially filled circle drawn on the canvas.
3. In the HTML file, add a canvas element inside the body element.
<canvas id="canvas">
</canvas>
HTML5 Programming 57
4. In the HTML file, add a script element with a draw function inside the head element, before the
head element’s closing tag.
<head>
...
<script type="text/javascript">
function draw() {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
}
5. At the end of the draw function, draw a rectangle with a radial gradient and three color stops.
<script type="text/javascript">
function draw() {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
context.beginPath();
context.arc(50, 75, 45, 0.5 * Math.PI, 1.5 * Math.PI);
context.fill();
context.beginPath();
context.rect(50, 30, 200, 90);
context.fill();
context.beginPath();
context.arc(250, 75, 45, 0.5 * Math.PI, 1.5 * Math.PI, true);
context.fill();
}
7. Run the saved file and show the students the completed webpage.
<canvas id="canvas">
</canvas>
4. In the HTML file, add a script element with a draw function inside the head element, before the
head element’s closing tag.
58 HTML5 Programming
<head>
...
<script type="text/javascript">
function draw() {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
}
5. At the end of the draw function, draw a circle skewed to look like an ellipse and translated to the
center of the canvas.
<script type="text/javascript">
function draw() {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
6. At the end of the draw function, draw text and rotate it.
<script type="text/javascript">
function draw() {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
...
context.rotate(Math.PI); // turn upside down
context.font = "bold 9px Arial";
context.fillStyle = "blue";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText("upside down", 0, 0); // draw the text "upside down" upside
down
}
8. Run the saved file and show the students the completed webpage.
HTML5 Programming 59
Lesson 2
Video/Audio Formats and Codecs
Contents:
Detailed Demonstration Steps 60
60 HTML5 Programming
4. In the HTML file, add a video element with built-in controls supporting automatic playback and
looping inside the body element.
6. Run the saved file and show the students the completed webpage.
HTML5 Programming 61
Lesson 3
Controlling Multimedia with JavaScript
Contents:
Detailed Demonstration Steps 62
62 HTML5 Programming
4. In the HTML file, add a video element with the id attribute and automatic playback inside the body
element.
5. Inside the head element, before the closing tag, add a script element that pauses and plays the
video.
<script type="text/javascript">
function toggleVideoPlayback() {
var video = document.getElementById("video");
if(video.paused) video.play();
else video.pause();
}
function contentLoaded() {
document.getElementById("video").addEventListener("click",
toggleVideoPlayback, false);
}
Answer: The primary considerations are the level of complexity of the application, support
for accessibility, and development speed.
64 HTML5 Programming
Module 6
Creating Advanced Graphics
Contents:
Lesson 1: Drawing with SVG 65
Lesson 2: Animation 68
HTML5 Programming 65
Lesson 1
Drawing with SVG
Contents:
Detailed Demonstration Steps 66
Additional Reading 67
66 HTML5 Programming
3. In the HTML file, add an svg element with the correct version and schema inside the body element.
9. Run the saved file and show the students the completed webpage.
HTML5 Programming 67
Additional Reading
Working with Shapes
• Attributes
Lesson 2
Animation
Contents:
Detailed Demonstration Steps 69
HTML5 Programming 69
3. In the HTML file, add an svg element with a blue circle containing various animations, inside the
body element.
5. Run the saved file and show the students how clicking the blue circle triggers the animations.
70 HTML5 Programming
Module 7
Using Client-Side Storage
Contents:
Lesson 1: Web Storage vs. Cookies 71
Lesson 1
Web Storage vs. Cookies
Contents:
Additional Reading 72
72 HTML5 Programming
Additional Reading
IndexedDB
• IndexedDB
HTML5 Programming 73
Lesson 2
Web Storage API
Contents:
Detailed Demonstration Steps 74
Additional Reading 76
74 HTML5 Programming
<body>
<form id="form1">
<p>
You have viewed this page <span id="counter"></span> times.
</p>
</form>
</body>
4. In the HTML file’s head element add the following script tag:
<script type="text/javascript">
function setCounter() {
if (!localStorage.getItem('numberOfPageLoads')) {
localStorage.setItem('numberOfPageLoads', 0);
}
localStorage.setItem('numberOfPageLoads',
parseInt(localStorage.getItem('numberOfPageLoads')) + 1);
document.getElementById('counter').innerHTML =
localStorage.getItem('numberOfPageLoads');
}
8. Run the project by pressing CTRL+F5 and show the students the completed web page
function logEventProperties(e) {
console.log(e.key);
console.log(e.oldValue);
console.log(e.newValue);
console.log(e.url);
console.log(e.storageArea);
}
5. Run the project by pressing CTRL+F5 and show the students the completed web page
76 HTML5 Programming
Additional Reading
Security and Privacy Considerations
• Web Storage Security and Privacy
HTML5 Programming 77
Answer: Client-side storage capabilities can help increase the performance of websites and
applications, reduce network latency by minimizing server calls, and help scale up the site or
application.
78 HTML5 Programming
Module 8
Using Advanced HTML5 JavaScript APIs
Contents:
Lesson 1: Using the Drag-and-Drop API 79
Lesson 1
Using the Drag-and-Drop API
Contents:
Detailed Demonstration Steps 80
Additional Reading 82
80 HTML5 Programming
<body>
<div id="draggableDiv" draggable="true" style="width:150px;
height:150px;border: solid 1px black;">The div can be dragged</div>
<div id="dropDiv" dropzone="copy" style="width:300px; height:300px; padding-
top:50px; border: solid 2px black;">a dropzone</div>
</body>
4. In the HTML file’s head element add the following script tag:
<script type="text/javascript">
function wireDragEvents() {
var div = document.getElementById('draggableDiv');
div.addEventListener('dragstart', handleDragStart, false);
function handleDragStart(ev) {
console.log('handling drag start event');
ev.dataTransfer.effectAllowed = 'copy';
ev.dataTransfer.setData("text", "stored text");
}
function handleDrop(ev) {
if (ev.stopPropagation) ev.stopPropagation();
console.log('handling drop event');
var data = ev.dataTransfer.getData("text");
console.log(data);
return false;
}
function handleDragOver(ev) {
if (ev.preventDefault) ev.preventDefault();
console.log('handling drag over event');
ev.dataTransfer.dropEffect = "copy";
return false;
}
9. Drag the first div and drop it inside the second div
Additional Reading
Dragging Events
• Drag and Drop
dataTransfer Object
• Data Transfer
Lesson 2
File API
Contents:
Detailed Demonstration Steps 84
Additional Reading 85
84 HTML5 Programming
<body>
<input type="file" id="file" name="file" multiple />
</body>
4. In the HTML file’s head element add the following script tag:
<script type="text/javascript">
function handleSelectedFiles(e) {
var files = e.target.files;
function contentLoaded() {
document.getElementById('file').addEventListener('change',
handleSelectedFiles, false);
}
8. Run the project by pressing CTRL+F5 and show the students the completed web page
9. Press the Browse button and pick any text file to see the result of the reading in the Visual Studio’s
console view
HTML5 Programming 85
Additional Reading
Security Considerations
• File API Security
86 HTML5 Programming
Lesson 3
Geolocation API
Contents:
Detailed Demonstration Steps 87
HTML5 Programming 87
3. In the HTML file’s head element add the following script tag:
<script type=”text/javascript”>
navigator.geolocation.getCurrentPosition(successCallback, errorCallback,
{
enableHighAccuracy: true,
maximumAge: 1000,
timeout:500
});
function successCallback(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
}
function errorCallback(error) {
var message = "";
switch (error.code) {
case error.PERMISSION_DENIED:
message = "Permissions denied by the user ";
break;
case error.POSITION_UNAVAILABLE:
message = "The current position could not be determined.";
break;
case error.PERMISSION_DENIED_TIMEOUT:
message = "timeout occurred ";
break;
}
console.log(message);
}
</script>
7. Run the project by pressing CTRL+F5 and show the students the completed web page
8. You should press the Allow Once button that is popped up by the browser
88 HTML5 Programming
Module 9
Using WebMatrix and Other Developer Tools
Contents:
Lesson 2: ASP.NET MVC 3 and Razor 89
HTML5 Programming 89
Lesson 2
ASP.NET MVC 3 and Razor
Contents:
Additional Reading 90
90 HTML5 Programming
Additional Reading
Design Patterns and Rationale for Using the ASP.NET MVC 3 Framework
• ASP.NET Webforms
• A loosely coupled system is a system whose components are minimally dependent on other
components in the system. This usually makes it easy to modify or replace components in a
predictable, isolated manner without affecting the rest of the system.
HTML5 Programming 91
Note Not all training products will have a Knowledge Base article – if that is the case,
please ask your instructor whether or not there are existing error log entries.
Courseware Feedback
Send all courseware feedback to [email protected]. We truly appreciate your time and effort.
We review every e-mail received and forward the information on to the appropriate team. Unfortunately,
because of volume, we are unable to provide a response but we may use your feedback to improve your
future experience with Microsoft Learning products.
Reporting Errors
When providing feedback, include the training product name and number in the subject line of your e-
mail. When you provide comments or report bugs, please include the following:
Please provide any details that are necessary to help us verify the issue.
Important All errors and suggestions are evaluated, but only those that are validated are
added to the product Knowledge Base article.