CS/COE 1520 pitt.edu/~ach54/cs1520 Storage One thing we haven't - - PowerPoint PPT Presentation

cs coe 1520
SMART_READER_LITE
LIVE PREVIEW

CS/COE 1520 pitt.edu/~ach54/cs1520 Storage One thing we haven't - - PowerPoint PPT Presentation

CS/COE 1520 pitt.edu/~ach54/cs1520 Storage One thing we haven't talked about is JS file I/O Because there isn't any! Why? So we just pull all information from the web? 2 Storage As part of HTML5, an API for Web Storage


slide-1
SLIDE 1

CS/COE 1520

pitt.edu/~ach54/cs1520

Storage

slide-2
SLIDE 2
  • Because there isn't any!

○ Why?

  • So we just pull all information from the web?

One thing we haven't talked about is JS file I/O

2

slide-3
SLIDE 3
  • As part of HTML5, an API for Web Storage was proposed

○ Has the browser allocate space for JS apps to store data on the client machine ■ Amount available per domain varies by browser

  • <4MB is a good rule of thumb

○ Data is stored as key/value pairs ■ Both strings

  • Two implementations of this API are available to JS apps:

○ localStorage ○ sessionStorage

Storage

3

slide-4
SLIDE 4
  • localStorage.length

○ Read only value ○ Number of key/value pairs stored in localStorage

  • localStorage.getItem(key)
  • localStorage.setItem(key, value)
  • localStorage.removeItem(key)
  • localStorage.key(index)

○ For a given index n, return the nth key in localStorage

  • localStorage.clear()

○ Remove all key/value pairs from localStorage

localStorage

4

slide-5
SLIDE 5
  • Has the same API as localStorage

○ Both implement Storage

  • However, sessionStorage is cleared as soon as the session
  • n the current page is ended

○ E.g., the browser window/tab is closed ○ When the same page is loaded in a different window/tab, a new session is created

  • Why would you use sessionStorage as opposed to simple

variable storage?

sessionStorage

5