-
Notifications
You must be signed in to change notification settings - Fork 2
/
cookie.js
55 lines (47 loc) · 1.67 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var Cookie = new Object();
Cookie.day = 86400000;
Cookie.week = Cookie.day * 7;
Cookie.month = Cookie.day * 31;
Cookie.year = Cookie.day * 365;
function getCookie(name) {
var cookies = document.cookie;
var start = cookies.indexOf(name + '=');
if (start == -1) return null;
var len = start + name.length + 1;
var end = cookies.indexOf(';',len);
if (end == -1) end = cookies.length;
return unescape(cookies.substring(len,end));
}
function setCookie(name, value, expires, path, domain, secure) {
value = escape(value);
expires = (expires) ? ';expires=' + expires.toGMTString() :'';
path = (path) ? ';path=' + path :'';
domain = (domain) ? ';domain=' + domain :'';
secure = (secure) ? ';secure' :'';
document.cookie =
name + '=' + value + expires + path + domain + secure;
}
function deleteCookie(name, path, domain) {
var expires = ';expires=Thu, 01-Jan-70 00:00:01 GMT';
(path) ? ';path=' + path : '';
(domain) ? ';domain=' + domain : '';
if (getCookie(name))
document.cookie = name + '=' + expires + path + domain;
}
function listCookies() {
var theCookies = document.cookie.split(';');
var aString = '';
for (var i = 1 ; i <= theCookies.length; i++) {
aString += i + ' ' + theCookies[i-1] + "\n";
}
return aString;
}
function DeleteCookies() {
var theCookies = document.cookie.split(';');
for (var i = 0 ; i < theCookies.length; i++) {
var mycookie = theCookies[i].split('=');
var cookiename = mycookie[0];
cookiename = cookiename.trim();
deleteCookie(cookiename);
}
}