HTML and CSS Reference
Figure 15-4: Stored data returned in an alert window.
h e main dif erence between session storage and local storage is that local storage is persistent.
Users can leave the site, turn of their computers, come back the next day, and the data are still
there. Local storage works very much like cookies, but there are certain dif erences that are
Cookies allow very little storage space; local storage allows far more.
Cookies are retransmitted automatically with every request to the server, and local
storage is not — which means local storage is far less work for the server and browser.
Local storage is transmitted on a request only.
Yo u ' l l i nd that localStorage and sessionStorage use the same getter/setter methods, so
once you know one, you know the other. However, you can set a value using localStorage ,
turn of your computer, go play a game of football, come home, turn on the computer, and your
data is still stored on your computer. h e following example ( LocalStorage.html in this
chapter's folder at www.wiley.com/go/smashinghtml5 ) shows how to store, retrieve, and
clear localStorage data.
< ! DOCTYPE HTML >
< html >
< head >