Web Storage for new features of HTML5

Source: Internet
Author: User
Tags sessionstorage

Web storage is a new feature of HTML5 that allows data to be stored in a local browser, enabling easy operation of the data and the ability to store up to 5M.

There are two types of WEB storage: Sessionstorage and Localstorage. Sessionstorage saves data when the browser is open and the data is discarded when the page is closed. Localstorage saved data will not disappear as the Web page and browser close, it will be saved locally, when the Web page opens again, the data still exists.

  

There are four common methods for WEB storage:

GetItem ("Key"); Get the data

SetItem ("Key", value); Storing data

RemoveItem ("Key"); Delete data

Clear (); Bulk Delete Data

Application Examples:

1 <!DOCTYPE HTML>2 <HTML>3 <HeadLang= "en">4     <MetaCharSet= "UTF-8">5     <title></title>6 </Head>7 <Body>8     <inputtype= "text"ID= "Text1">9     <inputtype= "button"value= "Session_set"onclick= "save_session ()">Ten     <inputtype= "button"value= "Session_get"onclick= "load_session ()"> One     <BR> A     <inputtype= "text"ID= "Text2"> -     <inputtype= "button"value= "Local_set"onclick= "save_local ()"> -     <inputtype= "button"value= "Local_get"onclick= "load_local ()"> the     <Script> -         functionsave_session () { -             varTarget=document.getElementById ("Text1"); -             varStr=Target.value; + Sessionstorage.setitem ("Text_message", str); -         } +         functionload_session () { A             varStr=Sessionstorage.getitem ("Text_message"); at alert (str); -         } -         functionsave_local () { -             varTarget=document.getElementById ("Text2"); -             varStr=Target.value; - Localstorage.setitem ("Text_message", str); in         } -         functionload_local () { to             varStr=Localstorage.getitem ("Text_message"); + alert (str); -         } the     </Script> * </Body> $ </HTML>

Link Address: http://1.huizit1.applinzi.com/HTML5/web_storage/webstorage.html

  

Web Storage for new features of HTML5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.