Showing posts with label HTML5. Show all posts
Showing posts with label HTML5. Show all posts

Saturday, 13 November 2010

HTML5 - Storing Data on the Client

Using HTML5, you can save data on clients (browsers) in two ways.
  • localStorage - This stores data with no time limit.
  • sessionStorage - This stores data for one session only।
How to create and access a localStorage:

<script type=“text/javascript”>
localStorage.firstname="Abdul";
localStorage.lastname="Ahad";
document.write( localStorage.firstname + " " + localStorage.lastname);
</script>

The following example counts the number of times a user has visited a page:

<script type="text/javascript">
if (localStorage.pagecount)
{
localStorage.pagecount=Number(localStorage.pagecount) +1;
}
else
{
localStorage.pagecount=1;
}
document.write("Visits "+ localStorage.pagecount + " time(s).");
</script>

The sessionStorage method stores the data for one session. The data is deleted when the user closes the browser window.

<script type="text/javascript">
sessionStorage.firstname="Abdul";
sessionStorage.lastname="Ahad";
document.write( sessionStorage.firstname + " " + sessionStorage.lastname);
</script>

The following example counts the number of times a user has visited a page, in the current session:

<script type="text/javascript">
if (sessionStorage.pagecount)
{
sessionStorage.pagecount=Number(sessionStorage.pagecount) +1;
}
else
{
sessionStorage.pagecount=1;
}
document.write("Visits "+sessionStorage.pagecount+" time(s) this session.");
</script>

Thursday, 23 September 2010

First HTML 5 example

HTML5 is a standard for structuring and presenting content on the World Wide Web. The new standard incorporates features like video playback and drag-and-drop that have been previously dependent on third-party browser plug-ins such as Adobe Flash and Microsoft Silverlight.

Here I am writting a sigle line of code (HTML5) to embed a video in your html page.

<html>
<body>

<video id="v1" src="http://htmlfive.appspot.com/media/billyBrowsers.ogg" controls></video>

</body>
</html>

simple video editor running in Safari

HTML5 specifies scripting application programming interfaces (APIs), some of them are;

  • The canvas element for immediate mode 2D drawing. See Canvas 2D API Specification 1.0 specification
  • Timed media playback
  • Offline storage database (offline web applications)
  • Document editing
  • Drag-and-drop
  • Cross-document messaging
  • Browser history management
  • MIME type and protocol handler registration.
  • Microdata
  • Geolocation
  • Web SQL Database, a local SQL Database
  • The Indexed Database API, a indexed hierarchical key-value store (formerly WebSimpleDB)