sessionstorage HTML5 sessionStorage session storage

   sessionStorage HTML5 is a new session storage object, the same window (or tab) used to temporarily store data, the data will be deleted after closing the window or tab. This part describes the sessionStorage (session storage) of use. Including add, modify, or delete operation.

 

1 Introduction 

1.1 Description

sessionStorage HTML5 is a new session storage object, the same window (or tab) used to temporarily store data, the data will be deleted after closing the window or tab.

In the JavaScript language you can call this object through the window.sessionStorage or sessionStorage.

 

1.2 Features

1) same-origin policy restrictions. If you want to operate on the same sessionStorage between pages, the pages must be in the same protocol, under the same host name and the same port. (IE 8 and 9 stores the same host name based on only the data required to ignore protocol (HTTP and HTTPS) and a port number)

2) single-label page limit. sessionStorage operating restrictions in a single tab, homology page views on this tab can be shared sessionStorage data.

3) only in the local store. seesionStorage data will not follow the HTTP request to the server together, will only take effect locally, and clear the data after you close the tab. (If you use Chrome's tab to restore function, seesionStorage data will be restored).

4) storage. seesionStorage storage methods use key, value manner. Value value must be a string type (passed non-string, it will be converted to a string .true values ​​are converted to "true" at the time of storage).

5) storage upper limit: limit different browser stores are not the same, but most browsers at the upper limit 5MB or less .

Accessible  http://dev-test.nemikor.com/web-storage/support-test/  storage limit test browser.

 

The minimum version 1.3 browser support

The minimum supported version of the browser sessionStorage: IE8, Chrome 5.

 

1.4 for the scene 

sessionStorage very suitable for SPA (single-page application), can easily be passed by value in the service module.

 

2. Members

2.1 Properties

Attributes readonly int sessionStorage.length: Returns an integer representing the data items stored in sessionStorage object (key-value pairs) number.

 

2.2 Method

method string sessionStorage.key (int index): Returns the name of the first key index numbers sessionStorage object. If there is no return null.

method string sessionStorage.getItem (string key): returns the key (key) corresponding to the value (value). If there is no return null.

method void sessionStorage.setItem (string key, string value ): This method accepts a key name (key) and the value (value) as a parameter, the key-value pair added to the store; if the key name exists, update the corresponding value.

method void sessionStorage.removeItem (string key): The specified key (key) is removed from the sessionStorage object.

method void sessionStorage.clear (): remove all items sessionStorage object.

 

3. Example

3.1 Data storage

3.1.1 the setItem () method stores

1
sessionStorage.setItem( 'testKey' , '这是一个测试的value值' );  // 存入一个值

3.1.2 attribute stored by  

1
sessionStorage[ 'testKey' ] =  '这是一个测试的value值' ;

  

3.2 to read data

3.2.1 value by the getItem () method

1
sessionStorage.getItem( 'testKey' );  // => 返回testKey对应的值

3.2.2 property values ​​by way of

1
sessionStorage[ 'testKey' ];  // => 这是一个测试的value值

 

3.3 storage Json objects

sessionStorage Json objects may also be stored: when storing, by the JSON.stringify () to convert the object text; reading, by the JSON.parse () converts the text to the subject.

1
2
3
4
5
6
7
8
9
10
11
12
var  userEntity = {
     name:  'tom' ,
     age: 22
};
 
// 存储值:将对象转换为Json字符串
sessionStorage.setItem( 'user' , JSON.stringify(userEntity));
 
// 取值时:把获取到的Json字符串转换回对象
var  userJsonStr = sessionStorage.getItem( 'user' );
userEntity = JSON.parse(userJsonStr);
console.log(userEntity.name);  // => tom

   sessionStorage HTML5 is a new session storage object, the same window (or tab) used to temporarily store data, the data will be deleted after closing the window or tab. This part describes the sessionStorage (session storage) of use. Including add, modify, or delete operation.

 

1 Introduction 

1.1 Description

sessionStorage HTML5 is a new session storage object, the same window (or tab) used to temporarily store data, the data will be deleted after closing the window or tab.

In the JavaScript language you can call this object through the window.sessionStorage or sessionStorage.

 

1.2 Features

1) same-origin policy restrictions. If you want to operate on the same sessionStorage between pages, the pages must be in the same protocol, under the same host name and the same port. (IE 8 and 9 stores the same host name based on only the data required to ignore protocol (HTTP and HTTPS) and a port number)

2) single-label page limit. sessionStorage operating restrictions in a single tab, homology page views on this tab can be shared sessionStorage data.

3) only in the local store. seesionStorage data will not follow the HTTP request to the server together, will only take effect locally, and clear the data after you close the tab. (If you use Chrome's tab to restore function, seesionStorage data will be restored).

4) storage. seesionStorage storage methods use key, value manner. Value value must be a string type (passed non-string, it will be converted to a string .true values ​​are converted to "true" at the time of storage).

5) storage upper limit: limit different browser stores are not the same, but most browsers at the upper limit 5MB or less .

Accessible  http://dev-test.nemikor.com/web-storage/support-test/  storage limit test browser.

 

The minimum version 1.3 browser support

The minimum supported version of the browser sessionStorage: IE8, Chrome 5.

 

1.4 for the scene 

sessionStorage very suitable for SPA (single-page application), can easily be passed by value in the service module.

 

2. Members

2.1 Properties

Attributes readonly int sessionStorage.length: Returns an integer representing the data items stored in sessionStorage object (key-value pairs) number.

 

2.2 Method

method string sessionStorage.key (int index): Returns the name of the first key index numbers sessionStorage object. If there is no return null.

method string sessionStorage.getItem (string key): returns the key (key) corresponding to the value (value). If there is no return null.

method void sessionStorage.setItem (string key, string value ): This method accepts a key name (key) and the value (value) as a parameter, the key-value pair added to the store; if the key name exists, update the corresponding value.

method void sessionStorage.removeItem (string key): The specified key (key) is removed from the sessionStorage object.

method void sessionStorage.clear (): remove all items sessionStorage object.

 

3. Example

3.1 Data storage

3.1.1 the setItem () method stores

1
sessionStorage.setItem( 'testKey' , '这是一个测试的value值' );  // 存入一个值

3.1.2 attribute stored by  

1
sessionStorage[ 'testKey' ] =  '这是一个测试的value值' ;

  

3.2 to read data

3.2.1 value by the getItem () method

1
sessionStorage.getItem( 'testKey' );  // => 返回testKey对应的值

3.2.2 property values ​​by way of

1
sessionStorage[ 'testKey' ];  // => 这是一个测试的value值

 

3.3 storage Json objects

sessionStorage Json objects may also be stored: when storing, by the JSON.stringify () to convert the object text; reading, by the JSON.parse () converts the text to the subject.

1
2
3
4
5
6
7
8
9
10
11
12
var  userEntity = {
     name:  'tom' ,
     age: 22
};
 
// 存储值:将对象转换为Json字符串
sessionStorage.setItem( 'user' , JSON.stringify(userEntity));
 
// 取值时:把获取到的Json字符串转换回对象
var  userJsonStr = sessionStorage.getItem( 'user' );
userEntity = JSON.parse(userJsonStr);
console.log(userEntity.name);  // => tom

Guess you like

Origin www.cnblogs.com/lxxzzz/p/11361939.html