为此,您可以在HTML5中使用本地存储。本地存储专为跨多个窗口且持续时间超出当前会话的存储而设计。特别是,出于性能方面的考虑,Web应用程序可能希望在客户端存储兆字节的用户数据,例如整个用户编写的文档或用户的邮箱。
<!DOCTYPE HTML> <html> <body> <script> if( localStorage.hits ){ localStorage.hits = Number(localStorage.hits) +1; } else{ localStorage.hits = 1; } document.write("总命中:" + localStorage.hits ); </script> <p>Refresh the page to increase number of hits.</p> <p>Close the window and open it again and check the result.</p> </body> </html