- //Page1.html
- < script >
- // Establish both types of storage data for a test
- localStorage.setItem("firstname", "Kaushik"); // persistent data
- sessionStorage.setItem("lastname", "S"); // persistent session data
- < /script> < a href = "page2.html" > Go to other page < /a>
Notice how sessionStorage data is not available when you open Page2.html in a new tab, or if the browser is closed. And notice how localStorage data remains persistent even in new browsing tabs and when browser is closed/opened.
- page2.html
- < script > document.write(localStorage.firstname + " " + sessionStorage.lastname); < /script>
Hiç yorum yok:
Yorum Gönder