web存储

两种存储方式localStorage和sessionStorage,由cookie完成。

localStorage:没有时间限制:

if (localStorage.pagecount)
  {
  localStorage.pagecount=Number(localStorage.pagecount) +1;
  }
else
  {
  localStorage.pagecount=1;
  }
document.write("Visits "+ localStorage.pagecount + " time(s).");

sessionStorage:针对一个session:

if (sessionStorage.pagecount)
  {
  sessionStorage.pagecount=Number(sessionStorage.pagecount) +1;
  }
else
  {
  sessionStorage.pagecount=1;
  }
document.write("Visits "+sessionStorage.pagecount+" time(s) this session.");

  

posted on 2014-11-13 21:17  j.w  阅读(143)  评论(0编辑  收藏  举报