In today's web development, HTML5 is one of the biggest topics we've talked about. HTML5 offers new features that empower web programmers and eliminate the effort to delve into ways to make websites better, faster, and more flexible. One of these new features that really interests me is Web Storage (Web Storage). Web Storage (Web Storage) provides a way to save user session information on the browser side. Let's take a look at the basic usage of Web Storage (Web Storage)!
Basic Essentials of Web Storage (Web Storage)
- The stored data can be structured data for any class JSON.
- The stored data does not expire as the session expires when the user browses, but is deleted at the user's request. Browsers also remove them because of storage space limitations or security reasons.
- The stored information can be used under the entire domain name.
Methods in Web Storage (Web Storage)
- SetItem (Key,value):
sessionStorage
adds a key/value data to the object.
- GetItem (Key): Gets the value based on key.
- Clear (): Empties the
sessionStorage
object.
- RemoveItem (key):
sessionStorage
deletes a data from the object.
- Key (N): Gets the value of key[n].
Setting the Key/value value
There are two ways to put information sessionStorage
in:
Sessionstorage.setitem (' Somekey ', ' somevalue ');
... You can also use a more concise approach:
Sessionstorage.somekey = ' somevalue ';
Gets a value:
There are also two ways to get a value:
// returns ' Somevalue '
... Or a simple reference sessionStorage
:
// returns ' Somevalue '
Delete a Key/value
// returns ' undefined ' for Somekey
All you need to do is to provide the key value to the removeItem
method.
Clear Data
// everything 's gone.
Simply call the clear () method, and nothing is needed.
A simple example of Web Storage (Web Storage) usage
<href= "javascript:;" OnClick = "If" (Sessionstorage && sessionstorage.getitem (' name ')) {alert (' Hurry back Oh, ' + sessionstorage.getitem (' name ') ); } "> logout </a>
When the user clicks the logout link, the page talks to the dialog box says "Hurry back Oh, xxx"!
Browser support for HTML5 Web Storage (web Storage)
The most critical feature of all cool features is the browser support, and fortunately, all modern browsers support HTML5 Web Storage (Web Storage), which is supported from the beginning of IE8. If you want to support IE6, IE7, then do it yourself.
HTML5 Web Storage (Web Storage) is very simple but also very useful. Because HTML5 Web Storage (web Storage) needs to operate with JavaScript, make sure that the browser supports this feature and turns on the Javascrpt scripting feature when using it to perform some key functions.
Do you think HTML5 Web Storage (Web Storage) is useful? Have they been used in your application?
Transfer from http://www.webhek.com/web-storage/
HTML5 Web Storage (Web Storage) technology and usage