H5 small content (6), h5 content

Source: Internet
Author: User
Tags sessionstorage

H5 small content (6), h5 content

Web Worker
Basic Content
Single thread and multi-thread
Worker can simulate the effect of multiple threads
Definition-javascript running in the background
Note-DOM cannot be used
Only ECMA in javascript can be used in Worker.
Currently, mainstream browsers support Worker, except for IE8
Worker provides APIs
Checks whether the current browser supports Worker.
If (typeof (Worker )! = "Undefined "){
Indicates that the current browser supports Web Worker
} Else {
The current browser does not support Web Worker.
}
Create a WebWorker object
New Worker (worker file)
Worker object
Onmessage event
PostMessage () method
Terminate () method
Web storage API
Basic Content
Data warehouse-used to store data
HTML5 Storage System
LocalStorage (Local Storage)-replace Cookie
SessionStorage (Session storage)-replace Session (similar to memory)
SessionStorage
SetItem (key, value) Method
Purpose: Set Data (New | modify data)
Add data-the key value is new
Changing the data-key value exists.
Parameters
Key-as the identifier of the stored data (unique and repeatable)
Value-stored data content (number | string)
GetItem (key) Method
Purpose: Get data (read data)
Parameters
Key-get the corresponding data content based on the key
Value corresponding to the returned value-key
Key (index) Method
Purpose: return the corresponding key based on the index value.
Parameters
Index-index value
Return Value-Return key value
RemoveItem (key) Method
Purpose: delete data
Parameters
Key-delete specified data content based on the key
Clear () method
Purpose: delete (empty) All data in the storage system)
Length attribute
Purpose: return the data count of the current storage system.
LocalStorage
The properties and methods provided are consistent with sessionStorage.
Storage event
Function-implement data sharing between multiple windows
Problem
Low Data Security
Currently, this event is not supported by all browsers except Safari.
Data Operations
Add-setItem ()
Query-getItem ()
Length attribute
Key (index)
Delete-removeItem ()
Clear ()
Modify
Key (index)-key
GetItem ()-value
SetItem (key, new value)
SessionStorage and localStorage
Features of sessionStorage storage system's data storage
When the browser window is closed, all data is lost.
When the browser window is opened again, data cannot be used
Features of data stored by the localStorage System
When the browser window is closed, data is still stored
When the browser window is opened again, data continues to be used
Data can only be deleted by users
Web Socket)
Basic Content
Socket-is a network protocol
Network Protocol-HTTP in SERVER & HTTP
WebSocket
Indicates that the socket protocol is allowed on the HTML5 page.
Browser-Server
Network protocol used-http protocol
Http protocol Problems
Transient connection
Stateless
APIS provided by WebSocket
Create a WebSocket object
Var socket = new WebSocket (URL );
URL-starting with "ws: //"
Create a Socket object and establish a connection
WebSocket object Method
Send ()-send data content to the server
Close ()-close the socket Link
WebSocket object events
Onmessage event-triggered when the server sends the returned data to the client
Onopen event-triggered when a connection is established between the client and the server
Complete Initialization
Onclose event-triggered when the link between the client and the server is closed
Release resources
Attributes of a WebSocket object
ReadyState Attribute-indicates the communication status of the server
CONNECTING (the number is 0), indicating that the connection is in progress.
OPEN (the number is 1), indicating that a connection has been established.
CLOSING (number value: 2) indicates that the connection is closed.
CLOSED (Number 2) indicates that the connection has been CLOSED.

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.