HTML5的新存储方式
2012-05-25 10:23
330 查看
1.sessionStorage
两个页面a.html,b.html
个人感觉sessionStroage和一个js的变量差不多,作用域是整个页面
2. localStroage
结论: localStroage和cookie的作用域一样
两个页面a.html,b.html
## a.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <script> sessionStorage.setItem('msg','hello world'); console.log(sessionStorage.getItem('msg')); </script> </body> </html> 打印结果 是 : hello world
## b.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <script> console.log(sessionStorage.getItem('msg')); </script> </body> </html> 打印结果 是 : null
个人感觉sessionStroage和一个js的变量差不多,作用域是整个页面
2. localStroage
#a.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <script> localStorage.setItem('msg','hello world'); console.log(localStorage.getItem('msg')); </script> </body> </html> #结果hello world
# b.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <script> console.log(localStorage.getItem('msg')); </script> </body> </html> #结果输出 hello world #当b.html的不在同一人域名下时输出为null
结论: localStroage和cookie的作用域一样
相关文章推荐
- 小白入门---HTML5中数据的存储方式
- HTML5 5大存储方式总结
- 前端HTML5几种存储方式的总结
- HTMl5的存储方式sessionStorage和localStorage详解
- html5web存储方式
- html5本次存储几种方式
- HTMl5的存储方式sessionStorage和localStorage详解
- 前端HTML5几种存储方式的总结
- webStorage是html5中用于本地化存储的一种方式
- HTML5存储方式
- HTML5 客户端存储数据的两种方式
- HTML5存储方式总结
- 前端HTML5几种存储方式的总结
- Storage---Html5 Web的5中离线存储方式之localStorage
- HTML5存储方式介绍
- html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage。
- html5本地数据库存储(database storage方式)
- HTML5 5大存储方式总结
- HTML5 Web 客户端五种离线存储方式汇总
- 前端HTML5几种存储方式的总结