What is HTML5 Web storage?
Use HTML5 to store the user's browsing data locally.
Earlier, local storage was using cookies. But Web storage needs to be more secure and fast. This data is not saved on the server, but it is used only for user requests for Web site data. It can also store large amounts of data without compromising the performance of the site.
Data exists as a key/value pair, and the Web page's data is only allowed to be used by that page.
- Save data: Localstorage.setitem (Key,value);
- Read data: Localstorage.getitem (key);
- Delete individual data: Localstorage.removeitem (key);
- Delete all data: Localstorage.clear ();
- Get the Key:localStorage.key (index) of an index;
Learn about local storage Next we use HTML5 's local storage to make a Notepad feature, and we need to download the layer component to the layer website
The specific code is as follows:
1 <!DOCTYPE HTML>2 <HTMLLang= "ZH-CN">3 <Head>4 <MetaCharSet= "UTF-8">5 <Metaname= "Viewport"content= "Width=device-width, initial-scale=1, maximum-scale=1, User-scalable=no">6 <title>Notepad</title>7 <Scriptsrc= "Http://www.jq22.com/jquery/jquery-1.10.2.js"></Script>8 <Scriptsrc= "Layer/layer.js"></Script>9 </Head>Ten <Body> One <Div> A <Buttontype= "button"onclick= "Notepad ()">Notepad</Button> - </Div> - the <Script> - //Notepad - functionNotepad () { - if(typeof(Storage)!== "undefined"){ //Check Browser support + varLocal=Window.localstorage, - Data=Local.getitem ("Memodata"); //to read locally stored information + layer.prompt ({ A Title:'Notepad', at FormType:2, - Value:data, - Area : ['500px', '400px'] //Custom text field width height - }, function(text, index) { - layer.close (index); - if(Data!=text) { in Local.removeitem ("Memodata"); //to delete locally stored information - Local.setitem ("Memodata", text); //store data information to local to } + }); - }Else{ the layer.msg ("I'm sorry. Your browser does not support Web Storage ..."); * } $ }Panax Notoginseng </Script> - </Body> the </HTML>
HTML5 Local Storage +layer layer components make Notepad