Web Storage包含2种。Session Storage
和Local Storage
。
Session Storage
Session Storage会在关闭流量器时被自动删除,它的生存和当前页面的生存时间一样,如果关闭当前页面,那么Session Storage中数据将被自动删除。
// Store value on browser for duration of the session
sessionStorage.setItem('key', 'value');
// Retrieve value (gets deleted when browser is closed and re-opened) ...
alert(sessionStorage.getItem('key'));
Local Storage
Local Storage不会在关闭流量器时被自动删除。
// Store value on the browser beyond the duration of the session
localStorage.setItem('key', 'value');
// Retrieve value (persists even after closing and re-opening the browser)
alert(localStorage.getItem('key'));
Other
- Cookie