The session storage stores the data till the user's session expires, i.e. user closes its browser window. The session object survives page refresh. In some browsers the value is restored on browser crash also. The difference between cookies and session storage is:

  • Session has data storage capacities in few MB’s as against cookies which is in KB’s.
  • Session storage data gets deleted on browser close command, tab change even for tabs of same browser, whereas, cookies are stored on the tab change.

The sessionStorage object is stored in the window object and can be accessed as window.seesionStorage.

The example below stores an user's input even on webpage reload. Without the sessionStorage, the data entered by user is set to null.

Example of sessionStorage object

 

›› go to examples ››