forked from myst729/JavaScript-Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookie.js
36 lines (29 loc) · 841 Bytes
/
cookie.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
/* JavaScript Cookie */
function CookieHandler() {}
CookieHandler.prototype.setCookie = function (name, value, seconds) {
if (typeof seconds !== 'undefined') {
var date = new Date()
date.setTime(date.getTime() + (seconds * 1000))
var expires = '; expires=' + date.toGMTString()
} else {
var expires = ''
}
document.cookie = `${name}=${value}${expires}; path=/`
}
CookieHandler.prototype..getCookie = function (name) {
name += '='
var carray = document.cookie.split(';')
for (var i=0; i < carray.length; i++) {
var c = carray[i]
while (c.charAt(0) === ' ') {
c = c.substring(1, c.length)
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length)
}
}
return null
}
CookieHandler.prototype.deleteCookie = function (name) {
this.setCookie(name, '', -1)
}