-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cookie.js
96 lines (87 loc) · 2.21 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function Cookies() {
var cookieData = [];
this.Read = function()
{
var pairs = new String(window.document.cookie).split(";");
var tmp, cookieName, keyName;
for (var i=0 ; i<pairs.length; i++)
{
tmp = pairs[i].split("=");
if (tmp.length == 3)
{
cookieName = new String(tmp[0]);
cookieName = cookieName.replace(" ", "");
if (cookieData[cookieName] == null)
cookieData[cookieName] = [];
cookieData[cookieName][tmp[1]] = unescape(tmp[1]);
}
else //length = 2
{
keyName = tmp[0];
keyName = keyName.replace(" ", "");
if (keyName.substring(0,12)!="ASPSESSIONID")
{
if (cookieData[""] == null)
cookieData[""] = [];
cookieData[""][keyName] = unescape(tmp[1]);
}
}
}
}
this.GetValue = function( cookie, key )
{
if (cookieData[cookie] != null)
return cookieData[cookie][key];
else
return null;
}
this.SetValue = function( cookie, key, value )
{
if (cookieData[cookie] == null)
cookieData[cookie] = [];
cookieData[cookie][key] = value;
}
this.Write = function()
{
var toWrite;
var thisCookie;
var expireDateKill = new Date();
var expireDate = new Date();
expireDate.setYear(expireDate.getFullYear() + 10);
expireDateKill.setYear(expireDateKill.getFullYear() - 10);
var pairs = new String(window.document.cookie).split(";");
var tmp, cookieName, keyName;
for (var i=0 ; i<pairs.length; i++)
{
tmp = pairs[i].split("=");
if (tmp.length == 3)
{
window.document.cookie = tmp[0] + "=" + tmp[1] + "='';expires=" + expireDateKill.toGMTString();
}
else
{
keyName = tmp[0];
keyName = keyName.replace(" ", "");
if (keyName.substring(0,12)!="ASPSESSIONID")
window.document.cookie = keyName + "='';expires=" + expireDateKill.toGMTString();
}
}
for (var cookie in cookieData)
{
toWrite = "";
thisCookie = cookieData[cookie];
for (var key in thisCookie)
{
if (thisCookie[key] != null)
{
if (cookie == "")
toWrite = key + "=" + thisCookie[key];
else
toWrite = cookie + "=" + key + "=" + escape(thisCookie[key]);
toWrite += "; expires=" + expireDate.toGMTString();
window.document.cookie = toWrite;
}
}
}
}
}