Skip to content

Commit ea5a8a2

Browse files
committed
added cookie.js
1 parent d5457b5 commit ea5a8a2

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

web/js/lib/cookie.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var today = new Date();
2+
var expiryyear = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
3+
var expirymonth = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000);
4+
var expiryday = new Date(today.getTime() + 24 * 60 * 60 * 1000);
5+
6+
function getCookie(name)
7+
{
8+
var reg= new RegExp("; "+name+";|; "+name+"=([^;]*)");
9+
var matches=reg.exec('; '+document.cookie+';');
10+
if (matches) return ((matches[1])?unescape(matches[1]):'');
11+
return null;
12+
}
13+
14+
function setCookie (name,value,expires,path,domain,secure)
15+
{
16+
document.cookie = name + "=" + escape (value) +
17+
((expires) ? "; expires=" + expires.toGMTString() : "") +
18+
((path) ? "; path=" + path : "") +
19+
((domain) ? "; domain=" + domain : "") +
20+
((secure) ? "; secure" : "");
21+
22+
return getCookie(name)!=null?true:false;
23+
}
24+
25+
function deleteCookie (name,path,domain)
26+
{
27+
if (getCookie(name)!=null)
28+
{
29+
document.cookie = name + "=" +
30+
((path) ? "; path=" + path : "") +
31+
((domain) ? "; domain=" + domain : "") +
32+
"; expires=Thu, 01-Jan-1970 00:00:01 GMT";
33+
}
34+
}
35+
36+
function cookieEnabled()
37+
{
38+
testCookieName="_testCookie_";
39+
if (setCookie(testCookieName,1))
40+
{
41+
deleteCookie(testCookieName);
42+
return true;
43+
}
44+
else return false;
45+
}

0 commit comments

Comments
 (0)