一、localStorage:本地的Session(硬件設備)javascript
特色:永久保存、java
代碼:瀏覽器
<script type="text/javascript"> if (localStorage.pagecount) { localStorage.pagecount=Number(localStorage.pagecount) +1; } else { localStorage.pagecount=1; } document.write("Visits "+ localStorage.pagecount + " time(s)."); </script>
效果:session
結果:關閉瀏覽器後,而後從本地硬盤獲取繼續累加this
二、sessionStorage :code
特色:臨時保存,關閉瀏覽器會失效ip
代碼:it
<script type="text/javascript"> if (sessionStorage.pagecount) { sessionStorage.pagecount=Number(sessionStorage.pagecount) +1; } else { sessionStorage.pagecount=1; } document.write("Visits "+sessionStorage.pagecount+" time(s) this session."); </script>
效果:io
結果:每次關閉瀏覽起Session就會從新刷新,能夠說SessionId不一樣了。class