In this tutorial you will learn more HTML and look atusing web storage. This will allow you to write a simple HTML site that you can then view in a web browser of your choice
About this Tutorial
Objectives
Delegates will learn to develop applications using HTML5/CSS3 and JS. After completing this course, delegates will be able to:
- Use Visual Studio 2012 effectively
- Create commercial HTML5 Web Applications
- Develop Websites that may use web sockets, animations and geolocation
Audience
This course has been designed primarily for programmers new to the .Net development platform. Delegates experience solely in Windows application development or earlier versions of HTML/CSS and JavaScript will also find the content beneficial.
Prerequisites
No previous experience in web programming is required. But any experience you do have in programming will help. Also no experience in browser IDE’s is required. But again any experience you do have with programming development environments will be a valuable.
Experience using a contemporary OO language such as C++ or C# would be useful but is not required.
Quick Access
Overview
Estimated Time – 1 Hour
Not what you are looking? Try the next tutorial – Files and Data
- Recap of Cookies
- HTML5 Web Storage is a successor to cookies
- So it makes sense to discuss cookies first
- Cookies are a well-established way to exchange small pieces of data between client and server
- Can be persisted (for a specified lifetime) on client’s computer
- Typically used to store user ID, etc.
- Have a scope (domain, application, page)
- Limitations of cookies
- Very limited in size (~4KB per cookie)
- Transmitted back-and-fore on every request scoped for that cookie
- HTML5 Web Storage is a successor to cookies
- The HTML5 Web Storage Approach
- In many cases where cookies are used traditionally, the same effect could be achieved without using a network
- This is where the HTML5 Web Storage API comes in …
- Developers can use the HTML5 Web Storage API to store values in local JavaScript objects
- The objects persist across page loads
- Additional notes:
- Stored data is not transmitted across the network
- Very large values can be stored (e.g. ~MB)
- Categories of Web Storage
- Local storage
- Accessible via window.localStorage
- Values are persisted even after you close the browser window
- To remove items from local storage, you must do so explicitly via JavaScript code (or if the user clears the browser’s cache)
- Values are accessible from the domain that initially stored the data
- Session storage
- Accessible via window.sessionStorage
- Values are discarded when the browser or tab is closed
- Values are accessible only from the page that stored the data
- Local storage
- Checking for Support
- You can easily check for Web Storage support – See TestWebStorageSupport.html
- View code file.
<script>
...
var localStorageMessageArea = document.getElementById("localStorageMessageArea");
var sessionStorageMessageArea = document.getElementById("sessionStorageMessageArea");
if (window.localStorage) {
localStorageMessageArea.innerHTML = "Browser DOES support localStorage";
} else {
localStorageMessageArea.innerHTML = "Browser DOES NOT support localStorage";
}
if (window.sessionStorage) {
sessionStorageMessageArea.innerHTML = "Browser DOES support sessionStorage";
} else {
sessionStorageMessageArea.innerHTML = "Browser DOES NOT support sessionStorage";
}
...
</script>
Lab 1: Understanding the Web Storage API
Lab 2: Listening for storage events
Lab 3: Offline working
Well done. You have completed the tutorial in the HTML5/CSS3/JS course. The next tutorial is
14. Files and Data
Copyright © 2016 TalkIT®
If you would like to see more content like this in the future, please fill-in our quick survey.