-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript1.js
48 lines (33 loc) · 1.02 KB
/
script1.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
let MyStorage = {
setItem: function(key, value) {
//check item exist or not
if (!this.getItem(key)) {
document.cookie = key + "=" + value + ";path=/;";
return true
}
return false
},
getItem: function(key) {
var key = key + "=";
var list = document.cookie.split(';');
for (var i = 0; i < list.length; i++) {
var value = list[i];
while (value.charAt(0) == ' ') {
value = value.substring(1);
}
if (value.indexOf(key) == 0) {
return value.substring(key.length, value.length);
}
}
return null;
},
removeItem: function(key) {
//check if exist or not
if (!this.getItem(key)) {
return false
}
// add old date so make it expire
document.cookie = key + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Path=/;';
return true
},
}