cs coe 1520
play

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


  1. CS/COE 1520 pitt.edu/~ach54/cs1520 Storage

  2. 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

  3. Storage ● 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 3

  4. localStorage ● 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 n th key in localStorage ○ ● localStorage.clear() ○ Remove all key/value pairs from localStorage 4

  5. sessionStorage ● Has the same API as localStorage ○ Both implement Storage ● However, sessionStorage is cleared as soon as the session on 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? 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend