二者都是本地存储所以不会给服务器额外的性能消耗
localStorage本地存储,localStorage是不受时间限制的,不像cookies它可以储存大数据,而对于不同的站点,存放的数据都在不同的area,在该站点也只能访问本area的localStorage数据
<script type="text/javascript">
function storage(){
if(Number(localStorage.pageCount)){
localStorage.pageCount=Number(localStorage.pageCount) +1;
}
else{
localStorage.pageCount=1;
}
document.write(localStorage.pageCount);
}
window.addEventListener("load",storage,true);
</script>
sessionStorage会话存储
<script type="text/javascript">
function storage(){
if (sessionStorage.pagecount)
{
sessionStorage.pagecount=Number(sessionStorage.pagecount) +1;
}
else
{
sessionStorage.pagecount=1;
}
document.write("Visits " + sessionStorage.pagecount + " time(s) this session.");
}
window.addEventListener("load",storage,true);
</script>
都是类似的,很简单,过去一些服务器和cookies在做的给分离了出来,并得到了强化