浏览器的 local storage
浏览器
- local storage 本地存储
- session storage 会话存储
- cookies 本地存储
- 1. local storage
local Storage 是解决cookies存储空间不足问题.
cookle中每条cookie的存储空间为4K.
local storage 的存储空间一般为5M.这个根据浏览器变化.
local storage 的值类型限定为string类型.如果存储内容多的话会导致页面变卡.
local storage 属于永久性存储.
- 2. local storage 的使用
1° 判断浏览器是否支持
if(!window.localStorage){
alert("浏览器支持localstorage");
return false;
}else{
//主逻辑业务
}
2° local storage 的写入
if(!window.localStorage){
alert("浏览器支持localstorage");
return false;
}else{
var storage=window.localStorage;
//写入a字段
storage["a"]=1;
//写入b字段
storage.a=1;
//写入c字段
storage.setItem("c",3);
console.log(typeof storage["a"]);
console.log(typeof storage["b"]);
console.log(typeof storage["c"]);
}
3° local storage 的读取
if(!window.localStorage){
alert("浏览器支持localstorage");
}else{
var storage=window.localStorage;
//写入a字段
storage["a"]=1;
//写入b字段
storage.a=1;
//写入c字段
storage.setItem("c",3);
console.log(typeof storage["a"]);
console.log(typeof storage["b"]);
console.log(typeof storage["c"]);
//第一种方法读取
var a=storage.a;
console.log(a);
//第二种方法读取
var b=storage["b"];
console.log(b);
//第三种方法读取
var c=storage.getItem("c");
console.log(c);
}
4° local storage的删除
1>清除所有
var storage=window.localStorage;
storage.a=1;
storage.setItem("c",3);
console.log(storage);
storage.clear();
console.log(storage);
2>删除某个键
var storage=window.localStorage;
storage.a=1;
storage.setItem("c",3);
console.log(storage);
storage.removeItem("a");
console.log(storage.a);
5° local storage 的键获取
var storage=window.localStorage;
storage.a=1;
storage.setItem("c",3);
for(var i=0;i<storage.length;i++){
var key=storage.key(i);
console.log(key);
}
浏览器的 local storage的更多相关文章
- Web持久化存储Web SQL、Local Storage、Cookies(常用)
在浏览器客户端记录一些信息,有三种常用的Web数据持久化存储的方式,分别是Web SQL.Local Storage.Cookies. Web SQL 作为html5本地数据库,可通过一套API来操纵 ...
- cookie ,session Storage, local storage
先来定义: cookie:是网站为了标识用户身份存储在本地终端的数据,其数据始终在APP请求中存在,会在服务器和浏览器中来回传递 数据大小不超过4k, 可以设置有效期,过了有效期自动删除 sessio ...
- Session,Cookie 和local storage的区别
以前从没有听说过local storage, 在网上查了一些资料,得到如下结论 从存储位置看,分为服务器端存储和客户端存储两种 服务器端: session 浏览器端: cookie, localSto ...
- 关于local storage 和 session storage以及cookie 区别简析
session storage 和local storage 都是存储在客户端的浏览器内: 一:关于COOKIE 的缺陷 * Cookie的问题 * 数据存储都是以明文(未加密)方式进行存储 * 安全 ...
- web页面缓存技术之Local Storage
业务:检测页面文本框的值是否有改变,有的话存入缓存,并存储到数据库,这样用户异常操作后再用浏览器打开网页,就可避免重新填写数据 数据库表:Test,包含字段:PageName,PageValue BL ...
- html5本地存储 local storage
HTML5 web storage, a better local storage than cookies. With HTML5, web pages can store data locally ...
- HTML5本地存储(Local Storage) 的前世今生
长久以来本地存储能力一直是桌面应用区别于Web应用的一个主要优势.对于桌面应用(或者原生应用),操作系统一般都提供了一个抽象层用来帮助应用程序保存其本地数据 例如(用户配置信息或者运行时状态等). 常 ...
- html5使用local storage存储的数据在本地是以何种形式保存的
html5使用local storage存储的数据是如何保存在本地的?(我使用的是chrome浏览器,chrom浏览器是用sqlite来保存本地数据的) Html5 的local storage 是通 ...
- 【JEECG技术博文】Local storage & easyui extensions
1. Local storage背景 cookie弊端:同域内http请求都会带cookie,添加带宽和流量:有个数和限制大小(约4K). 在HTML5中,本地存储是一个window的属性.包含loc ...
随机推荐
- MySQL Workbench查看和修改表字段的Comment值
查看: 选择单个表->[右键]->[Table Inspector] 再选择Columns选项卡即可,把表格拉倒最后一列. 编辑: 选择单个表->[右键]->[Alter Ta ...
- php 生成订单号
最近在练手一个订单提交的小项目,需要用到生成订单号,网上找了下,觉得这个最好. function build_order_no(){ return date('Ymd').substr(implode ...
- springMVC和ckeditor图片上传
springMVC和ckeditor图片上传 http://blog.csdn.net/liuchangqing123/article/details/45270977 修正一下路径问题: packa ...
- 1.3-动态路由协议EIGRP
EIGRP(Enhanced IGRP) EIGRP的特点: IGRP/EIGRP都是CISCO的私有协议. 1:是唯一的一种LS/DV的混合协议. 2:Rapid convergence EIGRP ...
- [Vue] Setup custom keyCode
Vue provide some shortcut methods: @mousemove.stop is comparable to e.stopPropogation() @mousemove.p ...
- Mysql经常使用函数
-----------------------------字符串函数--------------------------------------- ----拼接字符串.不论什么字符串与null拼接为n ...
- 日常工作中常见的mysql优化技巧
1.介绍一下MYSQL经常使用的优化技巧. MySQL 自带 slow log 的分析工具 mysqldumpslow ,可是没有说明.本文通过分析该脚本,介绍了其用法. slow log 是 MyS ...
- linux下.a/.so/.la目标库区别
在linux平台上编译时,常会遇到目标库的疑问,有静态库也有动态库,单个理解都不太难,但是对复杂的工程而言,一旦混合到一起去,对整个工程的理解和调用,将会造成很大困扰,本文就汇总这几种常见编译结果文件 ...
- 查看mysql是否安装成功和mysql的版本信息
转自:https://blog.csdn.net/hellocsz/article/details/81241204 使用快捷键win+R打开 进入mysql的安装目录下的\bin(本人安装路劲为E: ...
- sort与sorted的区别
描述 我们需要对List进行排序,Python提供了两个方法对给定的List L进行排序 : 方法1.用对List的成员函数sort进行排序 方法2.用内置函数sorte ...