There are many local storage solutions, such as Flash sharedobject, Google Gears, cookies, DOM Storage, User Data, Window.name, Silverlight, Open database, etc.
Take a picture of the web to see the current mainstream local storage scenarios:
Cookies: Widely used in the web, but the limitations are very obvious, the capacity is too small, some sites will be disabled for security reasons Cookie,cookie is not as safe as imagined, the content of the Cookie will be sent to the server along with the page request.
Flash Sharedobject: Use the Kissy store module to invoke Flash Sharedobject. The advantage of Flash Sharedobject is that the capacity is moderate, there is basically no compatibility problem, the disadvantage is to introduce a specific SWF and JS files in the page, add additional burden, processing cumbersome, or some of the machine does not have a flash operating environment.
Google gears:google Offline program, has stopped updating, the official recommended to use the HTML5 localstorage solution.
User Data: Microsoft for IE specifically in the system to open up a piece of storage space, so that only support windows+ie combination, the actual test in the IE5.5, XP (IE6, IE7), Vista (IE7) can be normal use. Under XP, generally located in the C:\Documents and Settings\ user name \userdata, sometimes in C:\Documents and Settings\ user name \application Data\microsoft\ Internet Explorer\UserData. Under Vista, the C:\Users\ user name is \appdata\roaming\microsoft\internet explorer\userdata; the size limit for a single file is 128KB, A total of 1024KB files can be saved under a domain name, the number of files should be unlimited. These values are 64KB and 640KB, respectively, in the restricted site, so a single file is best able to control 64KB or less if a variety of situations are considered.
Localstorage: Compared with the above-mentioned local storage scheme, Localstorage has its own advantages: large capacity, easy to use, strong, native support; The disadvantage is that compatibility is poor (Chrome, Safari, Firefox,ie 9,IE8 all support Localstorage, mainly IE8 the following versions are not supported), the security is also worse (so do not use Localstorage to save sensitive information).
Localstorage browser compatibility in HTML5 is as follows:
HTML5 provides two new ways to store data on the client:
- Localstorage-Data storage with no time limit
- Sessionstorage-Data storage for a session
Previously, these were all done by cookies. However, cookies are not suitable for storing large amounts of data because they are passed by each request to the server, which makes the cookie slow and inefficient.
In HTML5, the data is not passed by each server request, but only when the data is used on the request. It makes it possible to store large amounts of data without compromising site performance.
For different sites, the data is stored in different regions, and a Web site can only access its own data.
HTML5 uses JavaScript to store and access data.
Localstorage method
The data stored by the Localstorage method has no time limit. Data is still available after the second, second, or next year.
Localstorage has three ways to set up and access local storage.
1 <HTML>2 <Head>3 <title>Localstorage of HTML 5</title>4 </Head>5 <Body>6 <Scripttype= "Text/javascript">7 if(window.localstorage) {8 Localstorage.a="Alan"9 document.write (LOCALSTORAGE.A);Ten localstorage['b']="is a"; One document.write (localstorage['b']); A Localstorage.setitem ("C","Good people"); - document.write (Localstorage.getitem ("C")); - } the </Script> - </Body> - - </HTML>
Effect (after running, remove the set of three lines of code will still be displayed): Localstorage processing the above assignment value, there are several uses:
Localstorage.removeitem (); Clear
Localstorage.clear ()//Clear All
Localstorage.length//How many keys to get
Localstorage.key ()//Get the stored key content
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <title>Localstorage of HTML 5</title>5 </Head>6 <Body>7 <Scripttype= "Text/javascript">8 //determine if the browser supports Localstorage9 if(window.localstorage) {Ten One Localstorage.a="Alan" A document.write (LOCALSTORAGE.A); - localstorage['b']="is a"; - document.write (localstorage['b']); the Localstorage.setitem ("C","Good people"); - document.write (Localstorage.getitem ("C")); - - //Localstorage.removeitem ();//Clear + //localstorage.clear ();//Clear All - //localstorage.length//How many keys to get + //Localstorage.key ();//Get the stored room content A at Localstorage.removeitem ("C");//Clear - document.write ("<br/> Length"+localstorage.length); - for(varI=0; I<Localstorage.length;i++){ - - document.write ("<br/>"+Localstorage.key (i)+"----->"+Localstorage.getitem (Localstorage.key (i))); - in } - } to </Script> + </Body> - the </HTML>