<!DOCTYPE html> <html> <body> <script> // validate thether this browser support storage if(window.localStorage){ console.log("support local storage"); } if(window.sessionStorage){ console.log("support session storage"); } addEntryForSessionStorage(); addEntryForLocalStorage(); printAllLocalStoreInfo(); printAllSessionStoreInfo(); /* ============================== session storage ============================== */ function addEntryForSessionStorage(){ var key = window.sessionStorage.length+1; var value = parseInt(Math.random()*1000); window.sessionStorage.setItem(key,value); } function printAllSessionStoreInfo(){ console.log("all session storage informaton is below."); var sessionStorage = window.sessionStorage; for(var i=0;i<sessionStorage.length;i++){ var key = sessionStorage.key(i); var value = sessionStorage.getItem(key); console.log(key+":"+value); } } /* ============================== local storage ============================== */ function addEntryForLocalStorage(){ var key = window.localStorage.length+1; var value = parseInt(Math.random()*1000); window.localStorage.setItem(key,value); } function printAllLocalStoreInfo(){ console.log("all local storage informaton is below."); var localStorage = window.localStorage; for(var i=0;i<localStorage.length;i++){ var key = localStorage.key(i); var value = localStorage.getItem(key); console.log(key+":"+value); } } </script> </body> </html>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。