HTML5 Local Storage +layer layer components make Notepad

Source: Internet
Author: User

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

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.