Use HTML5 Web Storage as a simple chat room, html5storage

Source: Internet
Author: User

Use HTML5 Web Storage as a simple chat room, html5storage

Preface:

Two months ago, I made a hard decision to make a comment on my dive (latent) blog Park for two years. Registered an account!

It's okay to visit the blog Park and other technical websites to find a good comment wall. I read the technologies used here. Ah! Stunned. It's HTML5. I have never touched it!

 

Again:

Therefore, I searched the relevant documents of the blog Park and found the following information:

@ # $ ^ % &*(

$ & ^ **(&(

Http://zzk.cnblogs.com? T = B & w = html5 % 20 Storage

# $ % & ^ &*(

% * (& () * % $

There are too many materials for you to read.

 

In HTML5, a new function is provided to save data locally on the client, which is the Web Storage function.

There are two types of Web Storage:SessionStorageClear with closed BrowserLocalStoragePermanent storage

I want to use HTML5 Web Storage as a simple chat room, which is very simple.

 

Let's look at the example:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <Html xmlns =" http://www.w3.org/1999/xhtml "> <Head> <title> html5 Storage </title> <script type =" text/javascript "> function showTime () {var tDate = new Date (); var tseconds = tDate. getSeconds (); if (tseconds <10) tseconds = '0' + tseconds; var timeStr = 'nowtime: '+ tDate. getFullYear () + '/' + (tDate. getMonth () + 1) + '/' + tDate. getDate () + ''+ tDate. getHours () + ':' + tDate. getMinutes () + ':' + tseconds; document. getElementById ('time '). innerHTML = timeStr; msg. innerHTML = ''; var dom =''; for (var I = 0, len = localStorage. length; I <len; I ++) {dom + = '<div>' + localStorage. getItem (localStorage. key (I) + '</div>'} if (localStorage. length> 20) {localStorage. removeItem (localStorage. key (0);} msg. innerHTML = dom; setTimeout (showTime, 1000) ;}</script>  

You can also try it: click on me (I used Sina's sae to get a few small applications. Thank you !)

No worries. wp personal blog: Proview ipinao can help me trample on it. Traffic is less than my salary

 

Postscript:

No one looks at it anyway. I made a mess. The boss is still staring at me.

Worried about being dismissed.

 

Poor literary talent. I have not read any books! Do not laugh. Do not spray!

Keep an eye on my public account: I don't know why my friends remember this name.

 


In HTMl5, can web storage store a large amount of data? How to solve the problem is better. If you have a tutorial, you can add points.

"WebStorage is suitable for storing a small amount of data. For a large amount of structured data, IndexedDB is required for processing.
IndexedDB is a data storage method in HTML5 that supports the storage of structured data. Different from Cookie and Web Storage, IndexedDB provides the ability to support grouping, circular access, searching, and filtering JavaScript objects. For the tutorial, you can go to Tudou and Youku to see "Buid New World". It seems that the sixth episode is about this"

When studying HTML5, I don't know what is the difference between Web Storage and cookie.

"Compared with cookies, Web Storage has many advantages, which are summarized as follows:
1. Larger storage space: 5 MB Storage space is available (different browsers provide different storage space), and the Cookie is only 4 kb
2. The stored content will not be sent to the server: When a Cookie is set, the Cookie content will be sent along with the request to the server, which is a waste of bandwidth for local storage data. The data in Web Storage only exists locally and does not interact with the server.
3. More rich and easy-to-use interfaces: Web Storage provides a richer set of interfaces, making data operations easier.
4. Independent storage space: each domain (including subdomains) has an independent storage space, and each storage space is completely independent, so it will not cause data confusion.
It's hard to select the best one"

Related Article

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.