-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.js
75 lines (54 loc) · 2.35 KB
/
storage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Manage Local Storage
function addToLocalStorage() {
// PSEUDO CODE
// First, create a variable userInput with HTML Element's userInput value
// IF userinput is not an empty string
// log the variable value
// get current local storage or empty string if not defined with localStorage.getItem(localStorageKey123)
// create new variable with previous local storage and append userInput and newline
// update the local storage with our new string value using localStorage.setItem(localStorageKey123, newValue)
// updateChatArea()
// ELSE
// console.warn("no user input entered")
// alert("No User Input to add to localStorage")
}
function clearLocalStorage() {
// console.log("clearing local storage...")
// localStorage.clear()
// updateChatArea()
}
// Manage Session Storage
// function addToSessionStorage() {
// var userInput = document.getElementById("userInput").value
// if (userInput != "") {
// console.log("adding " + userInput + " to Session Storage")
// // get current session storage or empty string if not defined
// var cSessionStorage = sessionStorage.getItem("sessionStorageKey123") || ""
// // reset session storage object with appended userInput and newline
// var newSessionStorage = cSessionStorage + userInput + "\n"
// sessionStorage.setItem("sessionStorageKey123", newSessionStorage)
// updateChatArea()
// } else {
// console.warn("no user input entered")
// alert("No User Input to add to sessionStorage")
// }
// }
// function clearSessionStorage() {
// console.log("clearing session storage...")
// sessionStorage.clear()
// updateChatArea()
// }
// Common
function updateChatArea() {
console.log("updating chat area...")
document.getElementById("localStorageContent").innerHTML = localStorage.getItem("localStorageKey123");
document.getElementById("sessionStorageContent").innerHTML = sessionStorage.getItem("sessionStorageKey123");
}
// On Start, Check to See if Client's Browser supports Web Storage
if (typeof (Storage) !== "undefined") {
console.log("browser supports local web storage")
updateChatArea()
} else {
alert("Your browser does not support local web storage!")
console.error("browser does not support local web storage!")
}