Guest User

Untitled

a guest
Jan 20th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. Local Storage
  2.  
  3. Lesson Objectives:
  4. -Read, write, and update with Local Storage
  5. -Change the view of a page when it is loaded based on stored data
  6. -Perform CRUD operations on items in local storage.
  7.  
  8. About:
  9. The Web Storage API provides mechanisms by which browsers can store Key-value pairs, in a much more intuitive fashion than using cookies. Local Storage is accessed via globally available object. Local Storage only supports strings so it is important to make use of JSON.stringify() and JSON.parse(). Local storage has a limit of 5 MB, or 2.5 million characters, per domain.
  10.  
  11. There are two mechanisms within Web Storage:
  12. -sessionStorage:
  13. A separate storage area for each area(tab) for the duration of the page session(as long as the browser is open, including page reloads and restores).
  14.  
  15. -localStorage:
  16. Does the same thing, but persists even when the browser is closed and reopened.
  17.  
  18. Mechanisms:
  19. window.localStorage -Stores data with no expiration date.
  20. window.sessionStorage -Stores data for one session.
  21.  
  22. Local Storage Methods:
  23. setItem() // Add key and value to local storage
  24. getItem() // Retrieve a value by the key
  25. removeItem() // Remove an item by key
  26. clear() // Clear all storage
  27. local storage // See all that is in you local storage
  28.  
  29. Example Code:
  30. localStorage.setItem('key', 'value') // Sets data in global object
  31. localStorage.getItem('key') // Gets the data in global object
  32. localStorage.removeItem('key') // Removes key-value pair from browser
  33. localStorage.clear() // Clears all localStorage
Add Comment
Please, Sign In to add comment