Window.sessionStorage
The sessionStorage property allows you to access a session Storage object for the current origin. sessionStorage is similar to Window.localStorage, the only difference is while data stored in localStorage has no expiration set, data stored in sessionStorage gets cleared when the page session ends. A page session lasts for as long as the browser is open and survives over page reloads and restores. Opening a page in a new tab or window will cause a new session to be initiated, which differs from how session cookies work.
It should be noted that data stored in either sessionStorage or localStorage is specific to the protocol of the page.
Syntax
// Save data to sessionStorage
sessionStorage.setItem('key',
'value');
// Get saved data from sessionStorage
var data = sessionStorage.getItem('key');
// Remove saved data from sessionStorage
sessionStorage.removeItem('key');
// Remove all saved data from sessionStorage
sessionStorage.clear();
Value
Example
The following snippet accesses the current domain's session Storage object and adds a data item to it using Storage.setItem().
sessionStorage.setItem('myCat',
'Tom');
The following example autosaves the contents of a text field, and if the browser is accidentally refreshed, restores the text field content so that no writing is lost.
// Get the text field that we're going to track
var field = document.getElementById("field");
// See if we have an autosave value
// (this will only happen if the page is accidentally refreshed)
if
(sessionStorage.getItem("autosave"))
{
// Restore the contents of the text field
field.value = sessionStorage.getItem("autosave");
}
// Listen for changes in the text field
field.addEventListener("change",
function()
{
// And save the results into the session storage object
sessionStorage.setItem("autosave", field.value);
});
Note: Please refer to the Using the Web Storage API article for a full example.
From: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
Window.sessionStorage的更多相关文章
- BOM 浏览器对象模型_Storage 接口 - window.sessionStorage - window.localStorage
Storage 接口 用于脚本在浏览器保存数据. 保存的数据都以“键值对”的形式存在.也就是说,每一项数据都有一个键名和对应的值. 所有的数据都是以文本格式保存 受同域限制 ---- 某个网页存入的数 ...
- Window.sessionStorage - Web API 接口参考 | MDN
参考:https://developer.mozilla.org/zh-CN/docs/Web/API/Window/sessionStorage sessionStorage 属性允许你访问一个 s ...
- HTML5 sessionStorage会话存储
sessionStorage 是HTML5新增的一个会话存储对象,用于临时保存同一窗口(或标签页)的数据,在关闭窗口或标签页之后将会删除这些数据.本篇主要介绍 sessionStorage(会话存储) ...
- 似懂非懂的localStorage和sessionStorage
一.区别 相信很多人都见过这两个关于HTML5的新名词!HTML5种的web storage包含两种存储方式:localStorage和sessionStorage,这两种方式存储的数据不会自动发给服 ...
- html5存储方式localstorage和sessionStorage
html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage. 区别:localStorage无时间限制,除非主动删除数据,否则永不过期:sessio ...
- 关于HTML5本地缓存技术LocalStorage 本地存储 和 SessionStorage
如果你想在用户访问的时候记录或者记住他们的行为,你会想到的是什么,cookie 和session.但今天告诉你还有两种或者说是1种吧 那就是html5的 LocalStorage 本地存储和 Sess ...
- Cookie, LocalStorage 与 SessionStorage
Cookie, LocalStorage 与 SessionStorage相同点 都是储存在用户本地的数据. 意义在于避免数据在浏览器和服务器间不必要地来回传递. 三者的特点 同属于html5 ...
- Html5浏览器缓存 sessionStorage 与 localStorage
一.sessionStorage: 浏览关闭会话结束就被清除:(不能跨页面) localStorage:永久保存: 二.使用 var storage = window.sessionStorage; ...
- 【原】灵活运用sessionStorage或者localStorage
有时,一个app中,后台并没有提供页面中对应的信息接口,需要前端在页面跳转时把某些信息带入下一个页面,一般想到用url后带参数的方法,但是有时需要带的参数过长,就不适合用这个方法了,所以用sessio ...
随机推荐
- MSDN WinUSB Example
The WinUSB user-mode library uses device interface classes to communicate with the kernel-mode USB s ...
- [Go] md5 加密 示例
package main import ( "crypto/md5" "encoding/hex" "fmt" "io" ...
- [Go] 如何正确地 抛出 错误 和 异常(error/panic/recover)?
序言 错误 和 异常 是两个不同的概念,非常容易混淆.很多程序员习惯将一切非正常情况都看做错误,而不区分错误和异常,即使程序中可能有异常抛出,也将异常及时捕获并转换成错误.从表面上看,一切皆错误的思路 ...
- <table>标签的结构和合并单元格的方法
1.<table>标签的结构 示例代码: <table border="1"> <caption>信息统计表</captio ...
- Visual Studio 2013 sqlce 配置(转)
Visual Studio 2013 把內建 SQL CE 的管理工具拿掉了 下载SQL Server Compact Toolbox by ErikEJ并安装 打开VS2013,新建一工程,在“视图 ...
- CentOS 安装 Redis (高可用)
原文:https://www.sunjianhua.cn/archives/centos-redis.html 下载地址: http://download.redis.io/releases/ 官方文 ...
- Informix存储过程
一.存储过程概述 存储过程是一个用户定义的函数,由存储过程语句(SPL) 和一组SQL语句组成,以可以执行代码形式存储在数据库中,和表.视图.索引等一样,是数据库的一种对象. 存储过程语言SPL(St ...
- 创建、修改、删除ORACLE表空间
//创建表空间 create tablespace MyFirstSpace datafile '/opt/oracle/app/oracle/product/9.2.0/dbs/MyFirstSpa ...
- linux文件名称查找which,whereis,locate
1. 文件名称查找 使用find查询时.因为磁盘查询.所以速度较慢. 所以linux下查询更常使用which, whereis, locate来查询,因为是利用数据库查询.所以速度非常快. 2. wh ...
- Android之防止反编译技巧
1. 判断程序是否运行在模拟器上 boolean isRunningInEmualtor() { boolean qemuKernel = false; Process process = null; ...